Last active
November 2, 2016 16:43
-
-
Save mmparker/2ed0d441805047da2d5cf5f20f62ddfe to your computer and use it in GitHub Desktop.
When working with a sqlite tbl, if_else() won't accept named arguments - but *will* accept unnamed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
# Set up a temp sqlite database | |
db <- src_sqlite(tempfile(), create = TRUE) | |
iris2 <- copy_to(db, iris) | |
# if_else with named true and false on a data.frame -> no problem | |
iris %>% mutate(Sepal.Size = if_else(Sepal.Length > 5, | |
true = "big", | |
false = "not big")) | |
# if_else with named true and false on the sqlite tbl -> | |
# Error in if_else(Sepal.Length > 5, true = "big", false = "not big") : | |
# unused arguments (true = "big", false = "not big") | |
iris2 %>% mutate(Sepal.Size = if_else(Sepal.Length > 5, | |
true = "big", | |
false = "not big")) | |
# it works if unnamed, however | |
iris2 %>% mutate(Sepal.Size = if_else(Sepal.Length > 5, | |
"big", | |
"not big")) | |
# Same problem with base::ifelse | |
iris2 %>% mutate(Sepal.Size = ifelse(Sepal.Length > 5, | |
yes = "big", | |
no = "not big")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment