On Thu, Feb 4, 2010 at 4:53 PM, Wade Wall <wade.w...@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]] ______________________________________________ R-help@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.