rticulate / import

An Import Mechanism For R
https://import.rticulate.org
Other
222 stars 14 forks source link

Unclear documentation on .character_only = TRUE affect on .into #57

Closed brshallo closed 2 years ago

brshallo commented 2 years ago

(This may be more my own misunderstanding but thought I'd open issue as found a bit unclear when reading through).

I was a bit confused by the documentation of .character_only impact on .into.

For example in the help file under the argument for .character_only it states:

(Note that this parameter does not apply to how the .into parameter is handled).

Which seems in-line with how the package works. However in the advanced usage section of the vignette it reads:

By setting .character_only=TRUE, all non-standard evaluation of the .from, .into and the ... parameters is disabled (other parameters are always evaluated in a standard way). Instead, the parameters are processed as character vectors containing the relevant values.

Which I felt like had contradicted documentation point above...?

Context

What I want to be able to do is something like:

pkg <- "tidyr"
pkg_env <- "package:tidyr"
fun <- "nest"
import::from(pkg, fun, .into = pkg_env , .character_only = TRUE)

Goal is that if I run above and then do find("nest") it will return "package:tidyr" but won't load other functions... but need to do programmatically for any pkg::fun()` pairing.)

The current approach I am using is what @torfason suggested as option at #53

pkg <- "tidyr"
env <- new.env()
env_nm <- "package:tidyr"
fun <- "nest"

import::from(pkg, fun, .into = {env}, .character_only = TRUE)
attach(env, name = env_nm)
torfason commented 2 years ago

I agree, this is a documentation bug in the vignette. The .into parameter is indeed handled differently from the other parameters. And because of the special curly handling of that parameter it would be tricky to align all the parameters while still maintaining backwards compatibility, so it is likely to remain that way in the foreseeable future.

So the fix is to be clear about this in the documentation. A PR is of course always appreciated, but so is the clear bug report, and the example usage seems like a good one to include in a section on the advanced use of the .into parameter.

torfason commented 2 years ago

This is both fixed, and with subsequent improvements to the .into parameter it's also obsolete.

I did a few updates to the documentation of this in the vignette (https://import.rticulate.org/articles/import.html should be up to date now). If you see anything, feel free to let me know.