-
Notifications
You must be signed in to change notification settings - Fork 60
Closed
Description
I am using dplyr inside a package and therefore do .data$var to avoid tidy evaluation R CMD check NOTEs
dtplyr translates this falsely inside a dplyr::if_else()
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)
tib_lazy <- tibble::tibble(num = 1:5) %>%
dtplyr::lazy_dt() %>%
dplyr::mutate(
# don't use .data$ -> works well
lvl = dplyr::if_else(num <= 3, "low", "high"),
# use .data$ in if_else -> the string ".data$" remains in the query
lvl_.data = dplyr::if_else(.data$num <= 3, "low", "high"),
# use .data$ in base ifelse -> works but doesn't call fifelse
lvl_alt = ifelse(.data$num <= 3, "low", "high"),
# use .data$ outside if_else works well
num_alt = .data$num * 10
)
# lvl_.data is NA
# note the string ".data$" in the fifelse query of the lvl_.data variable
tib_lazy
#> Source: local data table [5 x 5]
#> Call: copy(`_DT1`)[, `:=`(lvl = fifelse(num <= 3, "low", "high"), lvl_.data = fifelse(.data$num <=
#> 3, "low", "high"), lvl_alt = ifelse(num <= 3, "low", "high"),
#> num_alt = num * 10)]
#>
#> num lvl lvl_.data lvl_alt num_alt
#> <int> <chr> <chr> <chr> <dbl>
#> 1 1 low <NA> low 10
#> 2 2 low <NA> low 20
#> 3 3 low <NA> low 30
#> 4 4 high <NA> high 40
#> 5 5 high <NA> high 50
#>
#> # Use as.data.table()/as.data.frame()/as_tibble() to access resultsCreated on 2021-03-08 by the reprex package (v1.0.0)
Metadata
Metadata
Assignees
Labels
No labels