I am a beginner with the {targets}
package, and I was wondering what is the right setup to register dependencies to functions (and datasets) developed by myself in an R data package.
My idea is to use {targets}
to develop the somewhat involved workflow of generating several exported datasets, and files on disk, for this hypothetical R data package of mine: {MyRDataPackage}
. And I would like those functions that generate these datasets/files to data-raw/
to be exported functions from the package itself, i.e. I would rather not have them sourced (as in source("R/functions.R")
) in _targets.R
.
By reading from Chapter 6.3 Dependencies , I got the feeling I could take this approach:
# _targets.R
tar_option_set(envir = getNamespace("MyRDataPackage"))
but reading a bit further, namely in Chapter 6.5 Packages-based invalidation, it seems I could also pass my {MyRDataPackage
} to the imports
argument:
# _targets.R
tar_option_set(
packages = c("MyRDataPackage"),
imports = c("MyRDataPackage")
)
So my question is: is either approach is fine? Or, are there reasons to prefer one over the other?
The guidance in Section 6.5 is the current recommendation. 6.3 is outdated but was just updated in https://github.com/ropensci-books/targets/commit/a9661e642beb174383222af16c1a599ae10a4735. Also answered at https://github.com/ropensci/targets/discussions/586\#discussioncomment-1140345.