Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store output of system command into a variable in r

I am executing the following command in R :

system("ls ") 

I need to store the output of the above command in some R variable. Is there a way to do the same??

like image 581
user1021713 Avatar asked Jun 19 '12 09:06

user1021713


People also ask

What does System () do in R?

🔗 Base system()/system2() R will convert this into the shell command that writes output to a temporary file, such as below. After the command exits with success, R tries to read the file and return the content.

How do I run a command in R?

To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.


2 Answers

Use intern=TRUE:

a <- system("ls ", intern = TRUE) 
like image 188
johannes Avatar answered Sep 18 '22 15:09

johannes


why not use the corresponding R function?

a <- list.files() b <- list.files(recursive = TRUE) 

For more details

?list.files 
like image 44
Thierry Avatar answered Sep 17 '22 15:09

Thierry