-
Notifications
You must be signed in to change notification settings - Fork 20
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
find calls for box
package use
#221
base: main
Are you sure you want to change the base?
Conversation
Thanks. While this change works, it also opens up too many possibilities for my taste. Can we, for the case of To be fair, the current code only works if |
You are right. After playing around a bit, I found some examples that work, but shouldn't work in my opinion: mtcars_rows <-
mtcars |>
duckplyr::as_duckplyr_tibble() |>
# There is no `test` package
duckplyr::mutate(row_num = test::row_number())
#> The duckplyr package is configured to fall back to dplyr when it encounters an
#> incompatibility. Fallback events can be collected and uploaded for analysis to
#> guide future development. By default, no data will be collected or uploaded.
#> → Run `duckplyr::fallback_sitrep()` to review the current settings.
mtcars_rows <-
mtcars |>
duckplyr::as_duckplyr_tibble() |>
# There is no `test` package and `box` is not used
duckplyr::mutate(row_num = test$row_number()) Created on 2024-08-19 with reprex v2.1.0 However, what should be possible, as this is a common use case with box::use(
test = duckplyr
)
#> The duckplyr package is configured to fall back to dplyr when it encounters an
#> incompatibility. Fallback events can be collected and uploaded for analysis to
#> guide future development. By default, no data will be collected or uploaded.
#> → Run `duckplyr::fallback_sitrep()` to review the current settings.
mtcars_rows <-
mtcars |>
test$as_duckplyr_tibble() |>
test$mutate(row_num = test$row_number()) Created on 2024-08-19 with reprex v2.1.0 So I think we should check for the following things:
What do you think? |
Thanks. Let's wait a bit, I have a code locally that handles the For the |
I was thinking of something like this at the top of name <- as.character(fun)
if (length(name) == 3) {
pkg <- name[[2]]
fun_name <- name[[3]]
if (name[[1]] == "::") {
# ... :: case ...
} else if (name[[1]] == "$") {
# Check that box is used
if(!isNamespaceLoaded("box")){
cli::cli_abort("Meaningful error")
}
# Check that pkg object is available in GlobalEnvironment
if(!exists(pkg, envir = env)) {
cli::cli_abort("Meaningful error")
}
fun_box <- eval(fun)
# Which namespace is the box object actually mapped to
pkg_ns <- getNamespaceName(environment(fun_box))[["name"]]
fun_mapped <- get(fun_name, envir = asNamespace(pkg_ns))
# Check that box function and mapped function are identical
if(!identical(fun_box, fun_mapped)) {
cli::cli_abort("Meaningful error")
}
return(c(pkg_ns, fun_name))
}
} So in the end the package name to which |
I noticed that the function translation doesn't work (yet) in combination with the
box
package:Created on 2024-08-07 with reprex v2.1.1
Session info
I suggest adding the
$
operator to the "fully qualified" package + name case. I also added an extra check thatlength(name) == 3
to avoid some (unexpected) nested special cases likelist$packagename$functionname()
.