From jeroenooms at gmail.com  Sun Feb  1 22:39:37 2015
From: jeroenooms at gmail.com (Jeroen Ooms)
Date: Sun, 1 Feb 2015 13:39:37 -0800
Subject: [Rd] Output to "raw console" rather than stdout/stderr?
In-Reply-To: <CAFDcVCSdMuxxFbOpw9-hHdRpUjXcvvoJPEo3QoFd9_9GGHqtMA@mail.gmail.com>
References: <CAFDcVCSdMuxxFbOpw9-hHdRpUjXcvvoJPEo3QoFd9_9GGHqtMA@mail.gmail.com>
Message-ID: <CABFfbXsoFdPapBq65Hp8dsx_yR_tUV3MQDKqaaKnxWgNebPA=g@mail.gmail.com>

Why do you need this? The sink system is often specifically needed to
capture such messages and display them to the user, for example in an
embedded environment. Many applications would not work when you bypass
the stdout/stderr set by the system. For example tools like knitr or
rapache need to capture stdout to get the output and insert it in a
report or webpage.

If you really want to, perhaps you could use something like
system("echo hello") to send a message to stdout via another process.


On Sun, Feb 1, 2015 at 11:13 AM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
> In R, there's readline(), which is great because you can prompt the user, e.g.
>
>     ans <- readline("Would you like to install Pandoc? [y/N]: ")
>
> without having to worry the message is intercepted by
> capture.output(), sink() or similar (which is used by dynamic report
> generators among other things).  The message will always reach the
> user.  (You can use sink(..., type="output") and sink(...,
> type="message") to confirm this.)
>
> Does anyone know of a similar function that outputs the message to
> "raw console" *without* pausing for user interrupt?  This far I came
> up with:
>
> cmsg <- function(...) {
>   if (.Platform$OS.type == "windows") {
>     pager <- "console"
>   } else {
>     pager <- "cat"
>   }
>
>   ## Write output to a temporary file
>   fh <- tempfile()
>   on.exit(file.remove(fh))
>   cat(..., file=fh)
>
>   ## Display file such that it cannot be captured/intercepted by R.
>   file.show(fh, pager=pager)
> }
>
> but if a less ad hoc approach exists, I'd like to hear about it.
>
> Thank you,
>
> Henrik
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] Output to "raw console" rather than stdout/stderr?
Jeroen Ooms