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

Henrik Bengtsson hb at biostat.ucsf.edu
Sun Feb 1 20:13:24 CET 2015

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()
  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,


More information about the R-devel mailing list