Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Make an all-NA variable logical #662
It seems like a variable that is filled with
readr::read_csv("v1,v2\nNA,NA") #> # A tibble: 1 × 2 #> v1 v2 #> <chr> <chr> #> 1 <NA> <NA> read.csv(text = "v1,v2\nNA,NA") #> v1 v2 #> 1 NA NA sapply(read.csv(text = "v1,v2\nNA,NA"), class) #> v1 v2 #> "logical" "logical"
I feel like I've raised this issue before and learned that the choice of character was somewhat deliberate? But now I can't remember why. Recent tidyverse ingest discussion supports a default to logical.
Was thinking of this because googlesheets runs data through
This behavior was defined in 1f352e5, the rational seems to be that if the first X values are missing readr will guess a charcter vector, so if there are non-missing values later they won't be lost, if we guess logical than non missing or T/F vales are lost.
referenced this issue
Jul 25, 2017
I have a new example of why logical
I want to do this:
You can see the problem with
reprex::reprex_info() #> Created by the reprex package v0.1.1.9000 on 2017-10-28 library(tidyverse) df1 <- read_csv("x,y\n1,\n") df2 <- read_csv("x,y\n3,4\n") bind_rows(df1, df2) #> Error in bind_rows_(x, .id): Column `y` can't be converted from character to integer rbind(df1, df2) ## "works" but is wrong because now y is character #> # A tibble: 2 x 2 #> x y #> <int> <chr> #> 1 1 <NA> #> 2 3 4 df1 <- read.csv(text = "x,y\n1,\n") df2 <- read.csv(text = "x,y\n3,4\n") rbind(df1, df2) %>% as_tibble() #> # A tibble: 2 x 2 #> x y #> <int> <int> #> 1 1 NA #> 2 3 4 bind_rows(df1, df2) %>% as_tibble() #> # A tibble: 2 x 2 #> x y #> <int> <int> #> 1 1 NA #> 2 3 4