Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store the console output to a variable in R

Tags:

terminal

output

r

In R I would like to store a console command to a variable. I have already tried with the solutions proposed in the following link but without luck: In R, is it possible to redirect console output to a variable? Here you are the command I'm using:

test <- capture.output(system("pa11y scuolafalconeborsellino.it; 
        perl -e \"print unpack('c', pack('C', $?)), \\$/\""), file = NULL)

The output visiblein the console is:

[4m[36m Welcome to Pa11y[39m[24m [90mWe'll sniff your page for you now. [39m [36m > [39mLoading page... [36m > [39mRunning HTML CodeSniffer... [36m > [39m[31mError: HTML CodeSniffer error[39m

-1

but the variable test is empty.

Thank you!

like image 686
Gianluca78 Avatar asked May 11 '15 08:05

Gianluca78


1 Answers

system has a parameter intern which can be used to save the output to a character vector:

test <- system("pa11y scuolafalconeborsellino.it; perl -e \"print unpack('c', pack('C', $?)), \\$/\"", 
               intern = TRUE)

Note that system2 is now prefered and system should be avoided in new code.

like image 96
Roland Avatar answered Sep 23 '22 08:09

Roland