2.0 KiB
2.0 KiB
Design of the internals
There are a lot of possible ways to implement this package, to minimize duplication. This is the API we want:
r(fun, args, ...)
r_safe(fun, args, ...)
r_bg(fun, args, ...)
r_bg_safe(fun, args, ...)
rcmd(cmd, cmdargs, ...)
rcmd_safe(cmd, cmdargs, ...)
rcmd_bg(cmd, cmdargs, ...)
rcmd_bg_safe(cmd, cmdargs ...)
The _safe
versions are easy to deal with, they just call the non-_safe
versions with different arguments.
For the other versions, this is what they need to do:
r
- convert / check arguments
- save function to a file
- create script file
- set up profiles
- set up library path
- set up LIB and PROFILE env vars
- set up callbacks (combine show and callbacks)
- run the R process
- write stdout & stderr to file, if needed
- fail on status, if requested
- get the result
r_bg
- convert / check arguments
- save function to a file
- create script file
- set up profiles
- set up library path
- set up LIB and PROFILE env vars
- start the R process in the bg
rcmd
- convert / check arguments
- get the R binary and its arguments
- set specified wd
- set up profiles
- set up library path
- set up callbacks (combine show and callbacks)
- set up LIB and PROFILE env vars
- run the R process
- write stdout & stderr to file, if needed
- fail on status, if requested
rcmd_bg
- convert/check arguments
- get the R binary and its arguments
- set specified wd
- set up profiles
- set up library path
- set up LIB and PROFILE env vars
- run the R process in the bg
Building blocks
Always run, check_my_args
:
- convert / check arguments
Run by r
and r_bg
, setup_script_files
:
- save function to a file
- create script file
Always run, setup_context
:
This is run with .
as the working directory for r
and r_bg
.
- set specified wd
- set up profiles
- set up library path
- set up LIB and PROFILE env vars