[Rd] Benchmark code, but avoid printing
hb at biostat.ucsf.edu
Fri Jan 2 21:00:08 CET 2015
On Fri, Jan 2, 2015 at 9:02 AM, Gábor Csárdi <csardi.gabor at gmail.com> wrote:
> Dear all,
> I am trying to benchmark code that occasionally prints on the screen
> and I want to
> suppress the printing. Is there an idiom for this?
> If I do
> then I'll be also measuring the costs of writing to tempfile. I could
> also sink to /dev/null, which is probably fast, but that is not
Interesting problem. On Windows NUL corresponds to /dev/NULL, e.g.
con <- file("NUL", open="wb"). Not that it's cross platform, but it
at least allows you to cover on more OS. Maybe R should have a
built-in "null" device. An easier solution is probably to go back to
the maintainers of the functions outputting text and ask them for an
option to disable that.
> Is there a better solution? Is writing to a textConnection() better?
For large number of output *lines* (not characters), textConnection()
is exponentially slow (at least in R 3.1.0). Use rawConnection()
instead, cf. http://www.jottr.org/2014/05/captureOutput.html
> Thanks, Best,
> R-devel at r-project.org mailing list
More information about the R-devel