Wednesday, April 13, 2011

R: Make sure command output is piped to sink()

In an R script when using sink() to output the results of commands to a file you will often get a blank file whereas if you copy and paste the same command into the R shell it will work fine. There are two ways round this:
  1. Wrap all commands with the print() fucntion
  2. When sourcing the file make sure that echo is set to TRUE i.e. source("input.r", echo=TRUE)