-
Notifications
You must be signed in to change notification settings - Fork 49
Callr module sourcing #199
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
Comments
Ah, that’s unfortunate. Apparently ‘callr’ uses a temporary file to invoke code via Unfortunately inside the subprocess ‘box’ has no way of knowing that it was invoked via ‘callr’, and from where. I think fixing this would require support from the ‘callr’ package, some way of hooking into the call and passing information into the child process. To work around this, you can explicitly set the script path via Here’s an example: box::use(callr)
callr$r(function (mod) {
box::set_script_path(mod)
box::use(./module)
}, args = list(mod = file.path(box::file(), '_'))) |
Actually it might be possible to handle this transparently without ‘callr’ cooperation by computing the script path when ‘box’ is loaded, and storing it in an environment variable (unless that variable is already set; in that case, assume that we’re inside a subprocess, e.g. via ‘callr’). Then, when The environment variable would need to be updated during the loading of a module (and reset afterwards) to support ‘callr’ invocations inside module source code. Edit: Nope, that fundamentally doesn’t work: normally, when the user invokes an external R script, they want that script to be standalone, i.e. act as its own module. ‘callr’ is special because it is (from the user perspective) invoked with an R function, not a script. |
Ah, that's a pity. Thank you for looking into this! The workaround you posted works nicely, so I can use that for the time being - thanks! |
Hello, I'm sorry but I still don't know how to use the workaround with {targets}. Could you please give some example code? |
This is still unclear to me and breaks targets pipelines when I try to use them with box. Namely, box doesn't search the
the targets pipeline is attempting to import the module, which I can import in an interactive R session using the following code
|
have continued a targets discussion re: compatability with box here ropensci/targets#936 (reply in thread) |
@pvtodorov Unfortunately I don’t currently have the time to debug this properly but my suspicion is that To try this, try including the following code inside either your calling script ( Sys.setenv(R_BOX_PATH = '/projects/petar/fgf1/code/') Regarding the incorrect dependency tracking of ‘targets’, this is presumably due to the fact that ‘targets’ internally resolves names using the ‘codetools’ package. Now, ‘codetools’ doesn’t know about the special meaning of |
Thanks for the quick reply and explanation. Here's the results for setting on the dependency tracking side, is there anything I can do as a user to wrap my box code, or run after it to accomplish the behavior I get with Example 3? |
I've been having trouble working with callr and box. Specifically, sourcing modules by `box::use(./module)' fails, as it appears that callr attempts to find them in a /tmp/ folder, rather than the working directory.
Might be related to #49?
Background info: I've come across this when using the {targets} package, where I have to specify
callr_function = NULL
in order to run the pipelineThe text was updated successfully, but these errors were encountered: