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

Jeroen Ooms jeroenooms at gmail.com
Sun Feb 1 22:39:37 CET 2015

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

More information about the R-devel mailing list