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) 0=================================================0 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 http://peabody.vanderbilt.edu/depts/psych_and_hd/faculty/wallern/ 0=================================================0 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>>>>> "Niels" == Niels Waller <niels.waller at vanderbilt.edu> writes: >>>>> "Niels" == Niels Waller <niels.waller at vanderbilt.edu> writes:Niels> I have written an R function that writes output to an Niels> external file using the sink function. I assume that Niels> `sink' is not operating system dependent. At the end Niels> of the function I have additional code that opens the Niels> newly created file using notepad on a Windows system. Niels> Obviously, this part of the code will not work on a Niels> Mac or Linux box. Since I do not have a machine with Niels> Linux or the Mac OS available I have no idea what to Niels> call the default editors. Could somebody provide a Niels> suggestion? Thanks in advance. Niels> win3 <- function(...) { Niels> system(...) Niels> } Niels> [a zillion lines of code here ] Niels> notepad.file <- paste("notepad", outFile, sep = " ") Niels> win3(notepad.file) Excuse me for not chiming in earlier. There is the ``only one correct'' (:-) solution of using getOption("editor") where it's assumed the user (or installer or OS default) has properly set options(editor = " ....") Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <>< -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
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. -Don 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) > > > > > >0=================================================0 >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 >http://peabody.vanderbilt.edu/depts/psych_and_hd/faculty/wallern/ >0=================================================0 > >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._