Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run shell script in R and get the output into table?

Tags:

shell

r

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().

like image 690
Pengyao Avatar asked May 21 '12 18:05

Pengyao


1 Answers

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) )
like image 130
IRTFM Avatar answered Oct 13 '22 13:10

IRTFM