edgararuiz-zz / dbplyr

Database (DBI) backend for dplyr
Other
1 stars 1 forks source link

is.na() produces Error: $ operator is invalid for atomic vectors #1

Open ablack3 opened 5 years ago

ablack3 commented 5 years ago

Hi @edgararuiz ,

This branch fixes an important issue for me and allows me to use %in% and case_when with MS SQL server. However it seems to create a new problem when I use is.na.

Any ideas what is causing the problem or how I can work around it?


library(dplyr)
con <- DBI::dbConnect(odbc::odbc(), Driver = "SQL Server", Server = "test_server", Database = "test_db")
mtcars_db <- tbl(con, "mtcars")
mtcars_db %>% 
  mutate(missing_mpg = ifelse(is.na(mpg), "missing", "not missing"))
#> Error: $ operator is invalid for atomic vectors
ablack3 commented 5 years ago

Ok I think I found a workaround.

This works...

mtcars_db %>% 
  mutate(tmp = is.na(mpg)*1) %>% 
  mutate(missing_mpg = ifelse(tmp == 1, "missing", "not missing")) %>% 
  select(mpg, missing_mpg)

But this does not.

mtcars_db %>% 
  mutate(tmp = is.na(mpg)) %>% 
  mutate(missing_mpg = ifelse(tmp, "missing", "not missing"))