I am layman to unix and sofar I using R in windows. For example I type following in my R session (in R gui).
# this is a my funny example script
X <- 1:10
Y <- 21:30
plot(X, Y)
myfun <- function (x){
x1 <- x^0.2
return (x1)
}
myfun(X)
How can I achieve this in unix shell, in two situations –
(1) directly in command line via an interpeter
(2) creating a script and running script.
Please provide step considering I am layman to unix.
Assuming you save your script in a simple text file with the name
so.R, you can run it under Linux/Unix by typingRat the prompt. Once in R enterto 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:
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.