[R] Rscript question

Jinfeng Liu jinfengl at gene.com
Fri Feb 19 20:45:41 CET 2010


OS <oozingslackitude <at> gmail.com> writes:
> Hi,
> I have some code I run interactively through the R interpreter and it works
> fine. I then run it as a script with Rscript and I get an error. The error
> is coming when Rscript builds a model matrix.
> 
> Output from Rscript with the error:
> running
>   '/usr/lib/R/bin/R --slave --no-restore --file=./matchingModel --args
> mmtest'
> ...

> Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
> could not find function "is"
> Calls: glm ... model.matrix -> model.matrix.default -> contrasts<-
> 

I ran into the same problems. Apparently, Rscript somehow doesn't automatically 
load the 'methods' package. The problem can be solved by adding

library(methods)

in your script.



More information about the R-help mailing list