Hi all, Is there a function to open a script file from the command line? I have several students who are Mac users and when they open up a script file it does not send commands to the console, and unfortunately I don't know how to solve this problem since I am not a Mac user. I have looked over the FAQ for Mac users, but didn't see a reference to the problem. I think they are both using OS X. Thanks for any help. Wade [[alternative HTML version deleted]]
On 5/02/2010, at 1:53 PM, Wade Wall wrote:> Hi all, > > Is there a function to open a script file from the command line? I have > several students who are Mac users and when they open up a script file it > does not send commands to the console, and unfortunately I don't know how to > solve this problem since I am not a Mac user. > > I have looked over the FAQ for Mac users, but didn't see a reference to the > problem. > > I think they are both using OS X. > > Thanks for any help.It's not clear to me what you are actually asking, since you (like 99.999% of people in the world, unfortunately) use the utterly stupid terminology ``open'', that the utterly stupid point-and-click interfaces to which everyone except me seems to be addicted, foists upon us. The word ``open'' is ambiguous. The script file contains code (R code). ``Opening'' the file could mean *editing* that code (with some text editor). But since you talk about ``sending the commands to the console'' I suspect that by ``opening'' you mean persuading R to execute the commands contained in the script. In which case see ?source. One can also ``send commands to the console'' via copy-and-paste. cheers, Rolf Turner ###################################################################### Attention: This e-mail message is privileged and confidential. If you are not the intended recipient please delete the message and notify the sender. Any views or opinions presented are solely those of the author. This e-mail has been scanned and cleared by MailMarshal www.marshalsoftware.com ######################################################################
On Feb 4, 2010, at 7:53 PM, Wade Wall wrote:> Hi all, > > Is there a function to open a script file from the command line? I > have > several students who are Mac users and when they open up a script > file it > does not send commands to the console, and unfortunately I don't > know how to > solve this problem since I am not a Mac user. > > I have looked over the FAQ for Mac users, but didn't see a reference > to the > problem.It is important when discussing Mac <-> R interactions to distinguish between the persons who run R from the command line and perhaps the larger group that uses the nicely designed R.app and r64.app GUI's. The GUI is missing some of the features that are present in the Windows GUI's, but it has other facilities missing in the Windows GUI. You can execute the console version with command line arguments. Your students may not know how to use the Terminal.app which will open up a shell window. You will need to decide whether to spend the time to teach them that useful skill set or not. This is what the R Mac FAQ says about external editors: "6.2 External editors R accepts the Apple Event command open. This means than an external editor can communicate with R sending portions of R code to execute via files. This is the approach used by the R-Tcl Mode in Alpha X (see http://www.kelehers.org/alpha/) . " You may find additional information here: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#What-happens-if-I-drag-a-file-on-the-R-icon_003f http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Finder-actions Best; -- David.> > I think they are both using OS X. > > Thanks for any help. > > Wade > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.David Winsemius, MD Heritage Laboratories West Hartford, CT
On Thu, Feb 4, 2010 at 4:53 PM, Wade Wall <wade.wall@gmail.com> wrote:> Hi all, > > Is there a function to open a script file from the command line? I have > several students who are Mac users and when they open up a script file it > does not send commands to the console, and unfortunately I don't know how > to > solve this problem since I am not a Mac user. > > I have looked over the FAQ for Mac users, but didn't see a reference to the > problem. > > I think they are both using OS X. > > Thanks for any help. > > Wade >Hello Wade, One way to execute the contents of a file containing an R script is through the command-line utility Rscript. This would be done by opening a terminal and using the following commands: cd path/to/script/files Rscript someScript.R On Linux and Unix machines, such as OS X, a the following hashbang line could be added to the top of the script: #!/usr/bin/env Rscript Then the script can be run from a terminal using: cd path/to/script/files ./someScript.R Or placed somewhere on the PATH and invoked from the command line by simply typing: someScript.R If your students don't know how to use the command line and absolutely have to get up and running quickly, the "double-click" the script functionality can be replicated: Right click (or control click for macs with one button) on someScript.R Choose "Get Info" from the context menu In the window that pops up, there should be an "Open With" section Click on the drop-down menu in the "Open With" section and select "Other..." Choose "All Applications" as the "Enable" option in the file browser that appears Select "Terminal" as the program to use. It should be located in: /Applications/Utilities/Terminal Check the "Always Open With" box and click add Click the "Change All..." button in the "Open With" section of the Get Info window Close the Get Info Window and double click scripts to your heart's content The above should work, however I feel like I should echo some of Rolf's sentiments concerning GUI usage (although hopefully a little more politely): 1. The GUI way is vastly more complicated ~9 steps compared to 2 and is inefficient-- each time a script is used, a new window is spawned which leads to clutter and chaos. Additionally these terminal windows "die" after the script finishes execution so there is no way to use them for anything other than viewing script output. 2. Any student learning to use a programming language *should be* taught a basic level of proficiency on the command line. They will run into it sooner or later and will be disadvantaged if they lack the skills to navigate and interact with command-line programs. That being said, I do some work in education too and I understand that in many cases the priority has to be to teach some sort of analysis technique to a lab full of students in a given amount of time using a given tool and the quicker that tool gets up and running the better. Hope this helps! -Charlie [[alternative HTML version deleted]]