Skip to content
Prev 80472 / 398502 Next

writing R shell scripts?

Mike Miller wrote:

            
What you ask R to do is

matrix(rnorm(25*2),c(25,2))

which is equivalent to

print(matrix(rnorm(25*2),c(25,2)))

What you really want to do might be solved by write.table(), e.g.

x <- matrix(rnorm(25*2),c(25,2));
write.table(file=stdout(), x, row.names=FALSE, col.names=FALSE);

A note of concern: When writing batch scripts like this, be explicit and use the print() statement.  A counter example to compare

echo "1; 2" | R --slave --no-save

and

echo "print(1); print(2)" | R --slave --no-save
If you want to be lazy and not use, say, doR 'cat(runif(1),"\n")' above, 
maybe a simple Unix sed in your shell script can fix that?!

/Henrik