rticulate / import

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

some_module.R - comments unclear #72

Closed HenningLorenzen-ext-bayer closed 1 year ago

HenningLorenzen-ext-bayer commented 1 year ago

Excerpts from some_module.R:

## This is also not recommended, because it is not clear wether recursively
## imported functions should be available after the module is imported
#import::here(qplot, .from = ggplot2)
## This is the recommended way to recursively import functions on which
## module functions depend. The qplot function will be available to
## module functions, but will not itself be available after import
import::here(qplot, .from = ggplot2)

Where is the point? Why is the former 'evil' and the latter 'good'? Both times it is import::here(qplot, .from = ggplot2)...

torfason commented 1 year ago

This seems to have been a typo in the example, the former should probably have been import::from(...). Also, it is no longer needed to use the named argument .from=... in import::here(...), so both arguments should simply have had ggplot2 as the first argument.

Fixed in dev, so it will make its way into main eventually, see some_module.R@dev:

## This is also not recommended, because it is not clear wether recursively
## imported functions should be available after the module is imported
#import::from(ggplot2, qplot)

## This is the recommended way to recursively import functions on which
## module functions depend. The qplot function will be available to
## module functions, but will not itself be available after import
import::here(ggplot2, qplot)

The upshot: Don't use library() or import::from() inside a module, use import::here().

Hope that helps!