store output of system command into a variable in r

user1021713 picture user1021713 · Jun 19, 2012 · Viewed 21k times · Source

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??

Answer

johannes picture johannes · Jun 19, 2012

Use intern=TRUE:

a <- system("ls ", intern = TRUE)