Search code examples
rconsolerstudio

Preserving long comments in console output. Not falling victim to ".... [TRUNCATED]"


I am trying to run a script that has lots of comments to explain each table, statistical test and graph. I am using RStudio IDE as follows

source(filename, echo=T)

That ensures that the script outputs everything to the console. If I run the following sequence it will send all the output to a txt file and then switch off the output diversion

sink("filenameIwantforoutput.txt")
source(filename, echo=T)
sink()

Alas, I am finding that a lot of my comments are not being outputted. Instead I get

"...but only if we had had an exclusively b .... [TRUNCATED]".

Once before I learned where to preserve the output but that was a few months ago and now I cannot remember. Can you?


Solution

  • Set the max.deparse.length= argument to source. You probably need something greater than the default of 150. For example:

    source(filename, echo=TRUE, max.deparse.length=1e3)
    

    And note the last paragraph in the Details section of ?source reads:

    If ‘echo’ is true and a deparsed expression exceeds ‘max.deparse.length’, that many characters are output followed by ‘ .... [TRUNCATED] ’.