Base R function system2 is the recommended way of invoking an operating system command from within R. It is portable across operating systems. Note that system2() never returns anything, to capture the OS command output in a character variable in the R session, arguments stdout or stderr must be set to TRUE.
Questions tagged [system2]
35 questions
17
votes
7 answers
R system functions always returns error 127
I need to execute an external tool from R and process errors (if any) occurred in that tool.
I know 3 functions to do something familiar with my task:
shell, system and system2.
Trying to test those, I see that command
shell("notepad")
opens…

Powerfool
- 299
- 2
- 3
- 9
15
votes
3 answers
Unable to get R language system2 command result
i am not able to get the system2 result. tried to execute the sample jar file.
execute_system.R:
workingDir <- "C:/Code"
setwd(workingDir)
command <- "java -jar sample.jar 674"
commandResult <- system2(command, stdout="C:/Code/stdout.txt",…

Jack
- 197
- 1
- 2
- 11
4
votes
1 answer
How does one terminate all processes upon Shiny app end?
I am using Shiny with a local server installed.
My Shiny app runs a heavy local program using system/system2/processx::run. I am running it synchronously (wait=T). If the user closes the browser window of the Shiny, I would love the heavy program to…

Sam
- 127
- 10
4
votes
0 answers
Embedded nul warnings when invoking system2 with stdout = TRUE on Windows
When trying to retrieve current process command line info using wmic via the system2 interface:
system2(
command = "wmic",
args = paste0("process where processid=", Sys.getpid(), " get commandline"),
stdout = TRUE
)
I get the following…

Jozef
- 2,617
- 14
- 19
3
votes
0 answers
Calling Java from R with System2 and Status 127
I am using RStudio on Windows.
system2("java C:/myClass", args = as.character(myVector))
Warning message:
running command '"java C:/myClass" 1 1 1' had status 127
From my understanding, this should mean that the command prompt is not able to…

Pippo
- 1,543
- 3
- 21
- 40
3
votes
1 answer
Redirect system2 stdout to a file on windows
According to the manual, the stdout argument of the system2 function can redirect output to a file. This seems to work on unix, however I can't get it to work on windows. The toy example below, no out.txt or err.txt files are created. I tried…

Jeroen Ooms
- 31,998
- 35
- 134
- 207
2
votes
0 answers
How can I feed a string that includes quotes to a system2 call in R?
I have a somewhat niche question that I'm hoping someone can answer for me or help me find a work-around to:
I've written a script in R that will run an ImageJ macro for sets of images I produce as a part of my workflow.
Because this is work that I…

Kelly N.
- 51
- 5
2
votes
1 answer
Add stdout = TRUE to R's system2 command and receive warning. Why?
I require the number of Firefox processes running on Linux (Ubuntu) be stored in a variable in an R script. By itself the system2 command I use seems to work. However, when I add stdout = TRUE to capture the info in a character vector I get a…

ixodid
- 2,180
- 1
- 19
- 46
2
votes
1 answer
R system2 run different scripts in parallel
I believe using system2() is a good option for running two R scripts in parallel. I'm trying something like the following:
Sys.time()
system2(command = 'Sys.sleep(5)', wait = FALSE)
system2('Sys.sleep(7)', wait = FALSE)
Sys.time()
However, it does…

Dario Federici
- 1,228
- 2
- 18
- 40
1
vote
1 answer
system2 command unzip not found
I have been trying to unzip multiple large files. I have been trying to use this function provided by Adam Bethke (see here) and below:
decompress_file <- function(directory, file, .file_cache = FALSE) {
if (.file_cache == TRUE) {
…

Anna Rouw
- 69
- 2
- 8
1
vote
1 answer
How to use the following command from R: echo "${pipestatus[1]}"?
I need to check the exit status of a piped command from R on Debian, like here, but cannot make run echo "${pipestatus[1]}" successfully from R using system2/system function. The command works properly when I use command line.
The command I am…

Nina Ilchenko
- 13
- 3
1
vote
0 answers
R system2 fails to exit after success
I am running an external executable, capturing the result as an object. The .exe is a tool for selection of a population based on genetic parameters and genetic value predictions. The program executes and writes output as requested, but fails to…

Andrew Sims
- 11
- 1
1
vote
0 answers
No result from system2 command
I have a script that I am using to analyse some audio data in R studio. The script runs with no errors however when I execute it, it simply does nothing. I think it may be an issue with the system2 command. Any help is much appreciated, I am at a…

Jenna
- 111
- 1
1
vote
0 answers
Looking for solution to R system2('powershell', args = readClipboard()) returning 127
I have the awkward problem that when executing a specific powershell command (calling a powershell Module located in ~/WindowsPowerShell/Modules/) in R via system2(command = 'powershell', args = someStringVariable) it will only return "127".
Other…

GWD
- 1,387
- 10
- 22
1
vote
0 answers
system2 does not save the output of a java command line to the file system, only output in console is created
I am trying to run a Java application (beagle2vcf) from R.
I tried with system() but no runs are performed only the help of the function is returned in the R console. But when I copy the same command to my cmd console the run is performed.
Then I…

Koen
- 11
- 2