According to help(Rscript)
, Rscript
doesn't load the methods package by default, because it's time-consuming. So you either need to specify it on the command line:
Rscript --default-packages=methods file.R
Or library(methods)
at the top of the file you're calling.