How to run shell script in R and get the output in

2019-04-29 13:17发布

问题:

I know to run a shell script in R is using system command:

my.table <- system(command,intern=TRUE)

However, if the result of my "command" is to print out a table, and I want R to read the table directly into its own data structure. (something like data frame) Is there an easy way to do that? Because the current output in "table" is a character string table. What I want is the R object as read.table().

回答1:

If the result 'table' has white-space separators and carriage-returns to mark lines, then you should pass the results to the 'text' argument of read.table:

 inp.tbl <- read.table(text = system(command,intern=TRUE) )


回答2:

I expect using pipe will be more efficient in memory and time than system with intern

inp.tbl <- read.table(pipe(command) )


标签: r shell