[R] calling an editor on MAC and Linux

Ott Toomet siim at obs.ee
Fri Jun 14 11:01:28 CEST 2002


Hi,

On Thu, 13 Jun 2002, Niels Waller wrote:

  |I have written an R function that writes output to an external file using
  |the sink function.  I assume that `sink' is not operating system dependent.
  |At the end of the function I have additional code that opens the newly
  |created file using notepad on a Windows system.  Obviously, this part of the
  |code will not work on a Mac or Linux box.  Since I do not have a machine
  |with Linux or the Mac OS available I have no idea what to call the default
  |editors.  Could somebody provide a suggestion?  Thanks in advance.
  |
  |
  |   win3 <- function(...) {
  |        system(...)
  |    }
  |
  | notepad.file <- paste("notepad", outFile, sep = " ")
  | win3(notepad.file)

If there is something like default editor, it is "vi" on UNIX (but there may
be 10-20 different editors with a full linux installation).  It is a general
tradition to let the user to define his own favourite using EDITOR
environment variable.  So, to be polite, you should check the presence of
the variable first, and thereafter run either vi or whatever was defined as
EDITOR.

This can be done pretty easily as (ignoring paste):

system("${EDITOR:-vi} outFile")

Unfortunately, this is not the whole story.  The previous example works with
bash shell (which is default command interpreter on Linux).  With tcsh,
another quite popular shell, I am afraid you need a different approach (this
again is controlled with environment variable SHELL).  In addition, many
editors in Unix are terminal-based (like vi) i.e., they do not open a new
window.  This may cause problems when R is runned from a GUI or from Emacs
(Emacs cannot interpret vi diplay-control strings correctly).  If runned as
usual process on a terimal, it is just fine.

Perhaps it is the best to try the example above, but warn the user and
suggest to customise the editor command.

Perhaps it helps.

Ott

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list