在控制台输出中保留长注释。不成为“......[截断]”的受害者
我正在尝试运行一个包含大量注释的脚本来解释每个表格、统计测试和图表。我正在使用 RStudio IDE,如下所示
source(filename, echo=T)
,这确保脚本将所有内容输出到控制台。如果我运行以下序列,它将把所有输出发送到一个txt文件,然后关闭输出转移,
sink("filenameIwantforoutput.txt")
source(filename, echo=T)
sink()
唉,我发现我的很多评论都没有被输出。相反,我得到
“......但前提是我们有一个专门的 b .... [截断]”。
之前我曾经了解过在哪里保存输出,但那是几个月前的事了,现在我不记得了。你可以吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将
max.deparse.length=
参数设置为source
。您可能需要大于默认值 150 的值。例如:并注意
?source
的“详细信息”部分中的最后一段内容如下:Set the
max.deparse.length=
argument tosource
. You probably need something greater than the default of 150. For example:And note the last paragraph in the Details section of
?source
reads:您可以通过覆盖
.Rprofile
中的source()
函数将此行为设置为默认行为。这似乎是覆盖函数的合理情况,因为从理论上讲,更改应该只影响屏幕输出。我们可以设计一个示例,但情况并非如此,例如,可以捕获屏幕输出并用作像
capture.output(source("somefile.R"))
这样的变量,但似乎不太可能。以更改返回值的方式更改函数可能会反过来影响您或与您共享代码的任何人(例如,如果您更改函数的na.rm
参数的默认值)。另一种方法是创建您自己的类似“别名”的函数。我在 .Rprofile 中使用以下内容:
You can make this behavior the default by overriding the
source()
function in your.Rprofile
.This seems like a reasonable case for overriding a function because in theory the change should only affect the screen output. We could contrive an example where this is not the case, e.g., can capture the screen output and use as a variable like
capture.output(source("somefile.R"))
but it seems unlikely. Changing a function in a way that the return value is changed will likely come back to bite you or whoever you share your code with (e.g., if you change a default of a function'sna.rm
argument).An alternative is to create your own 'alias'-like function. I use the following in my .Rprofile: