[R] calling an editor on MAC and Linux

Don MacQueen macq at llnl.gov
Fri Jun 14 21:49:34 CEST 2002

Mac OS X comes with vi and emacs, so existing R methods work:

   > sink('foo.doc') ; ls() ; sink()
   > edit(file='foo.doc')

If the desire is to use one of the OS's "native" editors, that is, 
one with a GUI and not a unix-based text editor, the following 
examples shos ways to do it.

   > system('open -e foo.doc')
to use the TextEdit application, or
   > system('open foo.doc')
which will use the default application for the ".doc" suffix. Or
   > system('open -a name.of.application foo.doc')
to use a specific application. But finding how the application is 
named in that particular context might not be easy.


At 8:05 PM -0500 6/13/02, 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(...)
>     }
>  [a zillion lines of code here ]
>  notepad.file <- paste("notepad", outFile, sep = " ")
>  win3(notepad.file)
>Dr. Niels G. Waller
>Quantitative Methods
>Department of Psychology and Human Development
>Box 512 Peabody College
>Vanderbilt University
>Nashville TN 37203
>email:  niels.waller at vanderbilt.edu
>fax:    615 343-9494
>QME home page: http://www.vanderbilt.edu/quantmetheval
>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

Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
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