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?
Running R from the Command Line To open up the command prompt, just press the windows key and search for cmd. When R is installed, it comes with a utility called Rscript. This allows you to run R commands from the command line.
To run an R command, put the cursor on the line of the command and then click the Run button at the top of the file window. Or just press CTRL-Enter.
You can open an R script in RStudio by going to File > New File > R script in the menu bar. RStudio will then open a fresh script above your console pane, as shown in Figure 1-7.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With