Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using if_else() results in error 'could not find function "fifelse"' #122

Closed
larspijnappel opened this issue Nov 12, 2019 · 9 comments
Closed

Comments

@larspijnappel
Copy link

I just installed dtplyr version 1.0.0 and it works like a charm. Unfortunately, when using the dplyr::if_else() function, it fails with the error message could not find function "fifelse".

library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

mtcars %>% 
    lazy_dt() %>%
    mutate(gear2 = if_else(gear == 5, 10, gear)) %>%
    as_tibble()
@hadley
Copy link
Member

hadley commented Nov 12, 2019

Try installing the latest version of data.table and see if works then?

@larspijnappel
Copy link
Author

Although my installed data.table package was already the latest version 1.12.6, I reinstalled it.
I also upgraded DT from v0.9 to v10.0.

But, after restarting, the issue remains..

@hadley
Copy link
Member

hadley commented Nov 12, 2019

It definitely works for me:

library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

mtcars %>% 
  lazy_dt() %>%
  select(gear) %>% 
  mutate(gear2 = if_else(gear == 4, 10, gear)) %>%
  as_tibble()
#> # A tibble: 32 x 2
#>     gear gear2
#>    <dbl> <dbl>
#>  1     4    10
#>  2     4    10
#>  3     4    10
#>  4     3     3
#>  5     3     3
#>  6     3     3
#>  7     3     3
#>  8     4    10
#>  9     4    10
#> 10     4    10
#> # … with 22 more rows

I'm not sure what's going on. Any ideas @MichaelChirico?

@larspijnappel
Copy link
Author

As pointed out by batpigandme in a related issue (#123 (comment)) the solution is to add library(data.table).

After re-reading your blog I noticed I missed this advice:

To use dtplyr, you must at least load dtplyr and dplyr. You might also want to load data.table so you can access the other goodies that it provides.

Sorry for overlooking this and thx for your help!

@MichaelChirico
Copy link
Contributor

would it make sense to detect data.table isn't loaded & include it in the lazy execution message?

@hadley
Copy link
Member

hadley commented Nov 13, 2019

Or possibly inject the data table functions we use directly into the evaluation environment.

@MichaelChirico
Copy link
Contributor

@hadley also might want to bump the data.table version dependency? fifelse/fcoalesce are from 1.12.4. Or otherwise branch on the package version to use fifelse only depending on the installed data.table version.

@MichaelChirico
Copy link
Contributor

For the injection part, I guess that's what's happening already for other data.table functions, is there any reason we didn't do this injection part initially? I guess we have to manually populate that environment with functions?

@hadley
Copy link
Member

hadley commented Nov 13, 2019

Yeah, I think I just forgot about that

hadley added a commit that referenced this issue Dec 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants