Run R Script - Ubuntu Server

2020-05-01 09:48发布

问题:

I've recently compiled R on Ubuntu Server 16.04. I'm attempting to run an R Script using the Rscript function, but I'm running into errors.

When I run the script using Rscript, the output shows the functions as() and new() from the methods package included in the R distribution cannot be found. When I run R interactively, I'm able to use these functions without any problem.

Any help would be tremendously appreciated!

回答1:

It is a design bug in Rscript: it does not load methods on startup.

Two fixes:

  1. Add library(methods) to your script, or
  2. Do sudo apt-get install r-cran-littler and use r instead of Rscript.

r has been loading methods since day one as this behaviour of Rscript never really made sense.