Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to capture system2() output in R

Tags:

r

Here is an example:

RR <- "/usr/bin/R"
x <- system2(RR, "--version")
R version 3.3.3 (2017-03-06) -- "Another Canoe"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.
> x
[1] 0

As you can see here the x is 0. My question is how to assign the system2(RR, "--version") output to x.

like image 307
David Z Avatar asked Mar 08 '17 21:03

David Z


1 Answers

This is described in the documentation for ?system2. If you want to capture the output of your program as a character vector, set stdout=TRUE

x <- system2(RR, "--version", stdout=TRUE)

"stdout" is for the "standard output" of the program. It's a common term used by programs to identify the "result" from a program.

like image 165
MrFlick Avatar answered Nov 04 '22 20:11

MrFlick