readxl
readxl copied to clipboard
Number >1 converted to boolean TRUE without any warning
In the following example, readxl returns TRUE instead of 599, without any warnings nor errors.
This doesn't happen with xlsx, openxlsx or openxlsx2.
I understand this is related to readxl guessing the column type using the first 1000 rows, but it should return at least a warning if not an error if the data it encounters is incompatible with the column type it guessed.
indf <- readxl::read_xlsx("test.xlsx")
indf %>% filter(project_id==1001) %>% pull("budget")
# returns TRUE
# should return 599
Yes, I agree. I was recently bitten by this problem - took about a day to figure out!
An alternate solution would be return a character vector rather than a logical vector. In this way, the full information can be captured, i.e. "599" which can be converted to numeric), or the calling program is more likely to return an error when doing arithmetic operations on a character column.
Carl Schwarz