-
Notifications
You must be signed in to change notification settings - Fork 74
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
Warn against devtools::load_all() in _targets.R #374
Comments
Hi @wlandau. I suspect the links in the warning need to be updated. https://books.ropensci.org/targets/practices.html#loading-and-configuring-r-packages leads to a 404. Perhaps https://books.ropensci.org/targets/packages.html#loading-and-configuring-r-packages is the intended URL? I can put a PR together for this tomorrow if you'd like. |
Thanks @mdneuzerling, 3e138e2 updates the links. |
Hi @wlandau, do you think this partially simulates # _targets.R in package root
# First load packages ("import()") and individual objects ("importFrom()") from the NAMESPACE file
for (imp in parseNamespaceFile(".", ".")$imports) {
if (length(imp) == 1) {
library(imp, character.only = TRUE)
} else {
import::from(imp[[1]], imp[[2]], .character_only = TRUE)
}
}
# And then objects from R/
for (file in fs::dir_ls("R/")) {
source(file, local = .GlobalEnv)
} |
To load scripts from within |
Prework
Proposal
devtools::load_all()
etc. are problematic fortargets
pipelines. It is best to fully install the packages usinginstall.packages()
or equivalent and set thepackages
and possiblyimports
options as described at https://books.ropensci.org/targets/practices.html#loading-and-configuring-r-packages and https://books.ropensci.org/targets/practices.html#packages-based-invalidation.Issues with
devtools::load_all()
and friends:tar_make_clustermq()
ortar_make_future()
.source("R/functions.R")
, then these functions will live in a special package environment wheretargets
does not find them by default. Unless you also set theimports
option,tar_visnetwork(targets_only = FALSE)
will not show them, andtar_make()
will not rerun the correct targets when you change your functions.There is not much we can do here except education, but we can at least try to statically crawl through
_targets.R
and throw a warning if symbols likeload_all
are detected. This warning should be suppressed ifSys.getenv("TAR_WARN")
is"false"
.The text was updated successfully, but these errors were encountered: