Replies: 5 comments 4 replies
-
Yeah, that's good practice. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply! I appreciate it and have been enjoying the utility targets brings to my projects. I suppose I am running into some additional friction trying to use @klmr's box package to manage my local code more explicitly instead of using Here are some minimal examples Example 1I have a options(box.path = '/projects/petar/fgf1/code/')
box::use(targets[tar_option_set,
tar_target],
blah/add_some_number[add_two,
add_four])
# Replace the target list below with your own:
list(
tar_target(two_added, add_two(2)),
tar_target(four_added, add_four(2))
) The
Example 2I've tried using box differently. Instead of importing functions, I import the whole module and call the functions from the imported module object using the options(box.path = '/projects/petar/fgf1/code/')
box::use(targets[tar_option_set,
tar_target],
blah/add_some_number)
# add_some_number = add_some_number
# add_another_number = add_another_number
# Replace the target list below with your own:
list(
tar_target(two_added, add_some_number$add_two(2)),
tar_target(four_added, add_some_number$add_four(2))
) Everything executes sucessfully and the module is tracked by targets. But if I make changes to either function within Example 3I noticed that if I set the functions exported by box equal to themselves as in options(box.path = '/projects/petar/fgf1/code/')
box::use(targets[tar_option_set,
tar_target],
blah/add_some_number[add_two,
add_four])
add_two = add_two
add_four = add_four
# Replace the target list below with your own:
list(
tar_target(two_added, add_two(2)),
tar_target(four_added, add_four(2))
) Calling Although this works, the code style is very strange and inconvenient. I am trying to figure out:
|
Beta Was this translation helpful? Give feedback.
-
Some additional experiments with setting |
Beta Was this translation helpful? Give feedback.
-
Hi, I was curious if this discussion has lead to a recommended way to use I noticed that Section 7.1 of The {targets} R package user manual states: "Some package management workflows are more complicated. If your use special configuration with conflicted, box, import, or similar utility, please do your configuration inside a project-level .Rprofile file instead of the target script file" Based on the above, I thought there might be an example of the recommended way to do this somewhere? Is it just option 3 from @pvtodorov additional experiments ?
So would Thanks so much! it would be very exciting and useful to get |
Beta Was this translation helpful? Give feedback.
-
Examples 2 and 3 both add something to the global environment, which is then tracked. For now, I am using a function to do Example 3 from above, i.e. adding each loaded function to the gobal env. Although if you do that, you might as well just # assumes all functions are in ./funcs/R
mods_to_globalenv <- function() {
box::use(stringr[ str_subset ], rlang[ search_env, env_names, env_get, global_env ])
mods <- str_subset(search(), "mod:funcs/R")
for (envname in mods) {
env <- search_env(envname)
for (fname in env_names(env)) {
f <- env_get(env, fname)
assign(fname, f, envir = global_env())
}
}
} |
Beta Was this translation helpful? Give feedback.
-
I'm trying to use targets with the box package.
I have the following code in my .Rprofile that sets a
box.path
telling the box package where to look for modules and scripts.This works in interactive sessions and I can load modules and scripts with box without an issues.
When I attempt to use
targets::tar_vistnetwork()
I get an error related to callr, which I've described here. I can solve this by calling the same options code above my box imports in my_targets.R
script.I'm not sure I understand how targets works at this level. Is it not sourcing the .Rprofile? Is there a way to get it do so? I would appreciate any guidance and help in understanding!
Beta Was this translation helpful? Give feedback.
All reactions