setClass not found when running R script from command line

1.3k views Asked by At

I have simple R script which trying to Define class. example.R

 Tuple <- setClass("Tuple",
            slots = c(
              id="character",
              comp="character",
              stream="character",
              task="character",
              output="vector",
              anchors="vector"
                )
            );

when i run Rscript example.R . i am getting an error saying below

Error in eval(expr, envir, enclos) : could not find function "setClass" Calls: source -> withVisible -> eval -> eval

can any one help?

1

There are 1 answers

2
Dirk is no longer here On BEST ANSWER

Rscript, in all its wisdom, does not load the standard methods package. So precede your script with

library(methods)

and all should be good.

If you're on Linux, you could use our littler package. It loads methods for you too, and starts a little faster than Rscript too.

Edit It is now some five years later and this has been added to Rscript in R release 3.5.0 or later.