Repository navigation
Have read_* functions parse non-traditional logicals #818
Description
Activity
You need to specify the columns are logical types when you read the data.
library(readr) lines <- "a,b A,true B,true C,false " read_delim(lines, ",", col_type = "cl") #> # A tibble: 3 x 2 #> a b #> <chr> <lgl> #> 1 A TRUE #> 2 B TRUE #> 3 C FALSE
Created on 2018-03-16 by the reprex package (v0.2.0).
Thanks, @jimhester, but I think you mistook my feature request for a question. I know about
read_delim(lines, ",", col_type = "cl")(that's how I created the desired behavior block of code). I want to know why functions likeread_delimare not smart enough to recognize non-traditional logicals on their own; howeverparse_logical()can. My feature request/enhancement is to replicate theparse_logical()behavior inside ofread_delim()so it is more robust to different types of logicals.The guesser currently does this
Line 35 in 31dfea0
return x == "T" || x == "F" || x == "TRUE" || x == "FALSE"; But the parser does an insensitive compare
Line 294 in 31dfea0
if (strncasecmp(string.first, "true", 4) == 0) { So yes we could change the guesser to do the same. If you would like to open a PR to do this it would be great, if not we will get to it eventually, but it may take some time.
- addedfeaturea feature request or enhancementa feature request or enhancement
on Mar 16, 2018 Thanks for taking a second look, @jimhester. No rush on implementing.
Here's how this is done in readxl, in case there is interest in doing same. It delegates the comparison back to R:
Thanks @jennybc, using
Rf_StringTrueseems like a good idea@jimhester It was probably your idea 😁
Oh yeah (tidyverse/readxl#277 (comment)), still thank you for reminding me about it and using it for this!
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/
- locked and limited conversation to collaborators
on May 15, 2019
Functions like
read_delim()andread_csv()do not recognize columns with logical data coded as "0/1" or "true/false", but it does recognize "T/F". This behavior is different thanparse_logical()which accepts all of the examples listed above. Is it possible to have these functions parse similar toparse_logical()?read_delim() Behavior
Desired Behavior
parse_logical() Behavior