From hb at biostat.ucsf.edu  Sun Feb  1 20:13:24 2015
From: hb at biostat.ucsf.edu (Henrik Bengtsson)
Date: Sun, 1 Feb 2015 11:13:24 -0800
Subject: [Rd] Output to "raw console" rather than stdout/stderr?
Message-ID: <CAFDcVCSdMuxxFbOpw9-hHdRpUjXcvvoJPEo3QoFd9_9GGHqtMA@mail.gmail.com>

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



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