-
Notifications
You must be signed in to change notification settings - Fork 129
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
Make it easier to load workflows structured as packages. #208
Comments
I don't really understand the proposed solution, but I can clarify exactly how we're using drake within the package structure.
While we are working on the scripts in When we are ready to run our code for real and save our results, we run The final product of this research project is an Rmd, so we also include a call to |
Looking at the content of |
If I understand correctly, you want to
Is there anything else? We might be able to combine |
Thinking about this some more, I think a better solution would be to concentrate on what happens after the package is loaded. Suppose we're using library(eply) # could be devtools::load_all() At this point, the usual behavior is the following. my_plan <- drake_plan(a = eply(1234)) # doesn't actually work, but good for demonstration here
config <- drake_config(my_plan)
vis_drake_graph(config) As with this comment from #227, drake finds nested functions inside the functions YOU define. However, it stops at packages in order to make projects less brittle (see [packrat](https://rstudio.github.io/packrat/ for a better way to depend on packages). But in this case, we care what's happening inside dive_into_package <- function(
package,
character_only = FALSE,
envir = parent.frame(),
jobs = 1
){
if (!character_only){
package <- as.character(substitute(package))
}
pkg_env <- getNamespace(package) %>%
as.list %>%
list2env(parent = globalenv())
lightly_parallelize(
X = ls(pkg_env),
FUN = function(name){
assign(
x = name,
envir = envir,
value = `environment<-`(get(name, envir = pkg_env), pkg_env)
)
},
jobs = jobs
)
envir
}
my_plan <- drake_plan(a = eply(1234))
config <- drake_config(my_plan)
vis_drake_graph(config) I would like to incorporate |
@dapperjapper in the several months that you have been using the hack, have you encountered any lexical scoping problems? Some alternative names:
|
|
Even better: |
Just need to add mentions in the appropriate vignettes.
Looks good! I think we need an example of how to use this within a package that is loaded with From the example, it looks like |
Side note: have you studied the quosure construct at all? I'm not sure if it would help with any of the complexity of managing drake dependencies across scopes, but I think it is a useful way to think about things. I've been thinking of making an experimental |
Thanks, @dapperjapper. Almost all of my focus is on #227, so I would really appreciate help. We could deep copy the package environment without modifying the original one. Somehow I missed the distinction. I'm just starting to get into tidy evaluation (see #200). I am not fluent yet, but I intend to be one day. From what little I know about quosures, they sound like a great way to manage scoping. This will definitely come into play for #233 and especially #247. |
Getting back to your question on which environments are modified: |
I just added new package-tracking functionality in |
From #30, environments populated with
pkgload::load_all()
look like package namespaces, and that can cause problems withdrake
workflows structured as packages. Frompkgload::load_code()
, it looksdevtools:::source_many()
would do most of the work. Thanks for the tip, @hadley!@dapperjapper For your workflows structured as packages, is there anything else you want to load? We could try to add on more components of
pkgload::load_all()
.We should also extend this part of the caution vignette.
The text was updated successfully, but these errors were encountered: