[R] Cannot use setClass() in Rscript

Martin Morgan mtmorgan at fhcrc.org
Wed Feb 15 22:12:25 CET 2012


On 02/15/2012 12:33 PM, Jonathan Callahan wrote:
> Greetings,
>
> I am creating a standalone executable script using Rscript and have run
> into problems when I define a new S4 class. Here is a small script that
> demonstrates my problem:

Hi --

Check out the difference between

   R --vanilla -e "sessionInfo()"

and

   Rscript --vanilla -e "sessionInfo()"

Rscript does not load the 'methods' package, so add require(methods) to 
your script.

Martin
>
> #!/usr/bin/env Rscript
> #
> # toy.Rscript -- testing S4 class creation in an Rscript
>
> setClass("toy",
>    representation(name = "character",
>                   price = "numeric"),
>    prototype(name = "ball",
>              price = 10.0)
> )
>
> b<- new("toy")
> print(b)
>
> When I make this script executable and run it I get the following error:
>
> $ ./toy.Rscript
> Error: could not find function "setClass"
> Execution halted
>
> Here is the relevant version information:
>
> $ Rscript --version
> R scripting front-end version 2.14.0 (2011-10-31)
>
> I am in the process of developing a set of S4 classes that I will
> eventually put into a package. I have been developing interactive scripts
> that can source the S4 class files without any problem. But now that I want
> to build a small command line 'wrapper' around my code I find that Rscript
> is not aware of "setClass".
>
> Any suggestions?
>
> Jon
>


-- 
Computational Biology
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109

Location: M1-B861
Telephone: 206 667-2793



More information about the R-help mailing list