subprocess_simple: Run R-Scripts In Parallell

Description Usage Arguments Details Value Examples

Description

'subprocess_simple' runs scripts in multiple processes but without duplicates.

Usage

1
2
3
subprocess_simple(script_paths, working_directory, process_limit = 3,
  overall_timeout = 60, print_stdout = F, print_stderr = F,
  debuglevel = 0)

Arguments

script_paths

(character) Paths to R-scripts.

working_directory

(character) Working directory for scripts. Recycled if neccessary.

process_limit

(integer) Number of processes to run in parallell (i.e. Rscript.exe instances).

overall_timeout

(integer) Maximum run time for all scripts. Then kills all processes and exits.

print_stdout

(logical) Print standard out from process?

print_stderr

(logical) Print standard error from process?

debuglevel

(integer) Print debug messages, 0 (nothing) to 3 (maximum).

Details

R scripts are run using Rscript.exe. Only one script with the same name, can run in parallell. Duplicates will be finished one at a time. Print-out from processes will carry a small time penalty when running. Always end the scripts with "quit(save = 'no')" .

Value

Value returned is vector of exit_codes for all (so far completed) scripts.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
## Not run: 
tmp1 <- c(
"print('Hello World! 1'); print(Sys.time()) Sys.sleep(sample(x = 3:10, size = 1)); quit(save = 'no')",
"print('Hello World! 2'); Sys.sleep(sample(x = 3:10, size = 1)); quit(save = 'no')",
"print('Hello World! 3'); Sys.sleep(sample(x = 3:10, size = 1)); quit(save = 'no')",
"print('Hello World! err'); Sys.sleep(sample(x = 3:10, size = 1)); stop('error here.'); quit(save = 'no')"
)
tmpf1 <- c(
  tempfile(fileext = ".R"),
  tempfile(fileext = ".R"),
  tempfile(fileext = ".R"),
  tempfile(fileext = ".R"))
for(i in 1:4) writeLines(text = tmp1[i], con = tmpf1[i])
subprocess_simple(script_paths = c(tmpf1, tmpf1),
                 working_directory = c("."),
                 process_limit = 5,
                 overall_timeout = 15,
                 print_stdout = T,
                 print_stderr = T,
                 debuglevel = 0)

## End(Not run)

dan070/subprocessrunner documentation built on May 9, 2019, 4:57 a.m.