Skip to content

Commit bf28082

Browse files
Include batchtools::runOSCommand() - to be patched
1 parent 6d5b0ba commit bf28082

File tree

3 files changed

+46
-2
lines changed

3 files changed

+46
-2
lines changed

DESCRIPTION

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
Package: future.batchtools
2-
Version: 0.20.0-9010
2+
Version: 0.20.0-9011
33
Depends:
44
R (>= 3.2.0),
55
parallelly,
66
future (>= 1.58.0)
77
Imports:
88
batchtools (>= 0.9.17),
9-
utils
9+
utils,
10+
checkmate,
11+
stringi
1012
Suggests:
1113
globals,
1214
future.apply,

NAMESPACE

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ importFrom(batchtools,saveRegistry)
9191
importFrom(batchtools,setJobNames)
9292
importFrom(batchtools,submitJobs)
9393
importFrom(batchtools,waitForJobs)
94+
importFrom(checkmate,"%??%")
95+
importFrom(checkmate,assertCharacter)
96+
importFrom(checkmate,assertString)
9497
importFrom(future,FutureBackend)
9598
importFrom(future,FutureError)
9699
importFrom(future,FutureInterruptError)
@@ -110,6 +113,8 @@ importFrom(future,tweak)
110113
importFrom(parallelly,availableCores)
111114
importFrom(parallelly,availableWorkers)
112115
importFrom(parallelly,supportsMulticore)
116+
importFrom(stringi,stri_flatten)
117+
importFrom(stringi,stri_replace_all_fixed)
113118
importFrom(tools,pskill)
114119
importFrom(utils,capture.output)
115120
importFrom(utils,file_test)

R/runOSCommand.R

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#' @importFrom checkmate assertCharacter assertString %??%
2+
#' @importFrom stringi stri_replace_all_fixed stri_flatten
3+
runOSCommand = function(sys.cmd, sys.args = character(0L), stdin = "", nodename = "localhost") {
4+
assertCharacter(sys.cmd, any.missing = FALSE, len = 1L)
5+
assertCharacter(sys.args, any.missing = FALSE)
6+
assertString(nodename, min.chars = 1L)
7+
8+
if (!isLocalHost(nodename)) {
9+
command = sprintf("%s %s", sys.cmd, stri_flatten(sys.args, " "))
10+
if (getRversion() < "4.0.0") {
11+
command = shQuote(command)
12+
}
13+
command = stri_replace_all_fixed(command, "\\$", "$")
14+
sys.args = c("-q", nodename, command)
15+
sys.cmd = "ssh"
16+
}
17+
18+
"!DEBUG [runOSCommand]: cmd: `sys.cmd` `stri_flatten(sys.args, ' ')`"
19+
20+
if (nzchar(Sys.which(sys.cmd))) {
21+
res = suppressWarnings(system2(command = sys.cmd, args = sys.args, stdin = stdin, stdout = TRUE, stderr = TRUE, wait = TRUE))
22+
output = as.character(res)
23+
exit.code = attr(res, "status") %??% 0L
24+
} else {
25+
output = "command not found"
26+
exit.code = 127L
27+
}
28+
29+
"!DEBUG [runOSCommand]: OS result (stdin '`stdin`', exit code `exit.code`):"
30+
"!DEBUG [runOSCommand]: `paste0(output, sep = '\n')`"
31+
32+
return(list(sys.cmd = sys.cmd, sys.args = sys.args, exit.code = exit.code, output = output))
33+
}
34+
35+
isLocalHost = function(nodename) {
36+
is.null(nodename) || nodename %chin% c("localhost", "127.0.0.1", "::1")
37+
}

0 commit comments

Comments
 (0)