store output of system command into a variable in r

RVariablesSystem

R Problem Overview


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

R Solutions


Solution 1 - R

Use intern=TRUE:

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

Solution 2 - R

why not use the corresponding R function?

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

For more details

?list.files

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1021713View Question on Stackoverflow
Solution 1 - RjohannesView Answer on Stackoverflow
Solution 2 - RThierryView Answer on Stackoverflow