[英]Suppress output in R
It's possible to suppress all the output but the cat/print/similar in an R console? 是否可以在R控制台中抑制除cat / print / like以外的所有输出?
I'm using SublimeRepl for Sublime Text and I would love to suppress the echo when executing a line (something like the ";" in matlab/octave), but keeping the output from cat/print or similar commands for obvious reasons. 我将SublimeRepl用于Sublime Text,并且我想抑制执行一行时的回声(类似于matlab / octave中的“;”之类的东西),但是出于明显的原因,保留cat / print或类似命令的输出。
Any idea? 任何想法?
There are a fair number of R functions that return values by way of the invisible
function. 有很多R函数通过
invisible
函数返回值。 They will cat
some limited set of values, but the returned object will be much larger. 它们将
cat
一些有限的值集,但返回的对象将大得多。 See for instance the code of lm
: 例如,参见
lm
的代码:
> invisible(strsplit(as.character(35600), split="..$"))
> invisible(print(strsplit(as.character(35600), split="..$")))
[[1]]
[1] "356"
The R console works by default as a read-eval-print loop and you need to emulate the read and eval segments but then invisibly return a value to the workspace. R控制台默认情况下是作为read-eval-print循环工作的,您需要模拟read和eval段,但随后会将值无形地返回到工作区。 I thought you might need to need to rewrite the
readline
function to get console output blanked out out. 我认为您可能需要重写
readline
函数,以使控制台输出被清空。 And probably need to fiddle with the stdin
and stdout
connections as well. 可能还需要摆弄
stdin
和stdout
连接。 Section 1.6, "Autoprinting" of the R Internals document will be required reading. 必须阅读R Internals文档的第1.6节“自动打印”。 It made me wonder if you could recompile R with the
R_Visible
variable set to FALSE. 这让我想知道是否可以将
R_Visible
变量设置为FALSE来重新编译R。 That section says "actual autoprinting is done by PrintValueEnv in file print.c
" 该部分说“实际的自动打印是由PrintValueEnv在文件
print.c
”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.