running r scripts or commands with interpretor in unix for unix-layman

后端 未结 4 745
情话喂你
情话喂你 2020-12-28 20:18

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:         


        
4条回答
  •  臣服心动
    2020-12-28 20:53

    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.

提交回复
热议问题