Comments (4)
I am not sure what you mean by "quote". You mean you want to call other functions from the same package? Then yes, use the package
argument.
from callr.
I am not sure what you mean by "quote". You mean you want to call other functions from the same package? Then yes, use the
package
argument.
yes, just use functions in the Global Environment, but callr
says "could not find function"
> add_1 <- \(x) return(x+1)
> loop_x <- function(){
+ i <- 1
+ while(TRUE) {
+ i = add_1(i)
+ readr::write_lines(i, "./data/x.txt")
+ Sys.sleep(1)
+ }
+ }
> rtask <- r(loop_x)
Error:
! in callr subprocess.
Caused by error in `add_1(i)`:
! could not find function "add_1"
Type .Last.error to see the more details.
in this case, I think the add_1
function is stored in the .GlobalEnv
, where package
argument by default directed to?
from callr.
Yes, that is by design, only the selected objects are copied to the subprocess. Copying the global environment is often a bad idea, if you have large objects, e.g. data sets in the global environment.
If you want to copy a set of functions, here is a way:
fun1 <- function() 1
fun2 <- function() 2
funcs <- list(fun1 = fun1, fun2 = fun2)
fun <- function(x, ..., funcs) {
x + funcs$fun1() + funcs$fun2()
}
callr::r(fun, list(x = 3, funcs = funcs))
#> [1] 6
If you want to copy the whole global environment, you can do that as well, but again, it might be a bad idea:
callr::r(fun, list(x = 4, funcs = as.list(.GlobalEnv)))
#> [1] 7
from callr.
Thanks for your patient explain! Now I understand why the global environment functions can't be read.
And your solution is quite inspiring, I almost forgot that functions can be put into a list()
😀
from callr.
Related Issues (20)
- Upkeep for callr (2023)
- Add alt-text to pictures, plots, etc; see https://posit.co/blog/knitr-fig-alt/ for examples
- Alternative to `arch` argument with `callr` v3.3.2 HOT 2
- r_bg processes hang when waiting for others to spawn HOT 2
- How to detect failure in `r_bg()` ? HOT 1
- Release callr 3.7.4
- please do not run unsigned dll files with random names from temp folder HOT 7
- Release callr 3.7.5
- callr update from CRAN HOT 1
- callr update from CRAN HOT 2
- Rtmp files left in /tmp directory with VSCode HOT 2
- callr update from CRAN HOT 3
- Release callr 3.7.6 HOT 1
- how to get out of session$attach() HOT 5
- Setting different R_HOME for the callr subprocess HOT 1
- r_process subclass shouldn't be cloneable HOT 1
- Spawn background processes across HPC cluster nodes HOT 1
- Use `testthat::with_mock()` instead of mockery
- `r_bg()` don't finished until run `rp$read_error()` and `rp$read_output()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from callr.