hadley / adv-r

Advanced R: a book

Home Page:http://adv-r.hadley.nz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Since Adv-R is now knitted with R 4.0, example results in 9.6.1 are no longer giving expected output. Fix: need stringsAsFactors = TRUE

yogat3ch opened this issue · comments

df <- data.frame(x = 1:3, y = c("a", "b", "c"))

detect(df, is.factor)

detect_index(df, is.factor)

It seems like Adv-R was last re-knitted with R 4.0 because these no longer return an answer that makes sense in the context.
image

L#971 needs to be updated to have stringsAsFactors = TRUE
df <- data.frame(x = 1:3, y = c("a", "b", "c"), stringsAsFactors = TRUE)

Something similar happens in the first example of section 3.6.1.
The text says that data.frame() converts character vector to factor, but this doesn't happens in the chunk code, probably because now, as @yogat3ch points out, Advance R is knitted with R 4.0

There is also mention of this in section 3.4.1:

In base R you tend to encounter factors very frequently because many base R functions (like read.csv() and data.frame()) automatically convert character vectors to factors.

There are also a few instances of setting the argument to FALSE when that is now the default (in addition to those already listed):

This issue is also raised by #1770 and #1636.