11

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 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or call with the namespace: methods::setClass(...
As an additional note - if you have this problem when running checks on a package (if you're using devtools to run checks, for example) - you can add import(methods) to your NAMESPACE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.