简体   繁体   中英

Suppress output in R

It's possible to suppress all the output but the cat/print/similar in an R console?

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.

Any idea?

There are a fair number of R functions that return values by way of the invisible function. They will cat some limited set of values, but the returned object will be much larger. See for instance the code of 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. I thought you might need to need to rewrite the readline function to get console output blanked out out. And probably need to fiddle with the stdin and stdout connections as well. Section 1.6, "Autoprinting" of the R Internals document will be required reading. It made me wonder if you could recompile R with the R_Visible variable set to FALSE. That section says "actual autoprinting is done by PrintValueEnv in file print.c "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM