running r scripts or commands with interpretor in unix for unix-layman
Assuming you save your script in a simple text file with the name so.R
, you can run it under Linux/Unix by typing R
at the prompt. Once in R enter
source('so.R')
to execute the script inside the R environment (this assumes the so.R file is in the same directory as you are when you issue this command).
To run the script from the Linux/Unix command line use the following command:
R CMD BATCH so.R
Note that I got the plot to show when I ran the script inside of R, but from the Linux command line it doesn't show. I suspect it gets quickly displayed and then goes away, so there will be a R command that you have to look up to make it pause after it displays the plot.
If your program is going to work on a single dataset, then simple-r might be the solution:
http://code.google.com/p/simple-r/
It is especially designed for simple statistical analysis as a part of Linux command line. For example, if one wants to plot some data, 'r -p data.txt' will do the job; for getting correlation coefficient: 'r cor data.txt' will suffice.
I'm guessing from the way you worded your question that you maybe SSH'ed into a linux machine? Or that you installed Ubuntu, for example, on your usual laptop/PC.
Assuming it's the second case: open a terminal and type sudo apt-get install r-base
. Then type R
. Then type
X <- 1:10Y <- 21:30plot(X, Y)myfun <- function (x){ x1 <- x^0.2 return (x1) }myfun(X)
Since your question is about unix
versus linux
rather than R
, you might also try http://unix.stackexchange.com. There is a lot to be said about the differences between linux and unix, but all you probably need to know is: download Ubuntu, burn it onto a disc, then restart your computer with the disc in your CD drive.
Hope this helps.