[R] Problem with factors in lm() when using Rscript but not GUI
Paul.Rustomji at csiro.au
Paul.Rustomji at csiro.au
Tue Mar 23 00:54:14 CET 2010
Hello R-help
I am having a curious problem. I am using a batch file to call an R script and am getting an error when performing a lm() fit using factorial data only when running in batch mode (see below). I do not get the error when executing the same code in GUI mode in R 2.10.1. Nor do I get the error when using Rscript version 2.9.2....
#######################################
#windows batch file contains this line to call tnp2.r r-script
#Rscript ./tnp2.r --slave
########################################
########################################
#tnp2.r - contents of tnp2.r script file are below
print(R.Version()$version.string)
#generate some data
x <- rep(c(1:12),3)
y <- 1:length(x)+rnorm(length(x))
print(x)
print(y)
#this bit works OK
xtemp <- lm(y ~ x )
print(xtemp)
print("got to here (without factor part)")
monthfac <- as.factor(x)
print(monthfac)
#this line below causes probs in R v2.10.1 when run from Rscript.....
xtemp2 <- lm(y ~ monthfac)
print(xtemp2)
stop("stopped on purpose",call.=F)
#end of file tnp2.r
###############################################
#error message is thus:
Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") :
could not find function "is"
Calls: lm ... model.matrix -> model.matrix.default -> contrasts<-
Execution halted
As I say - all works ok in GUI mode but not in Rscript mode (v2.10.1).....
This problem seemed to commence after upgrading to R 2.10.1 from R2.9.2, as the same code works fine in Rscript in version 2.9.2.
Paul.
###########################
> Sys.info()
sysname release
"Windows" "XP"
version nodename
"build 2600, Service Pack 3" "XXXX"
machine login
"x86" "xxxxxx"
user
"xxx"
$platform
[1] "i386-pc-mingw32"
$arch
[1] "i386"
$os
[1] "mingw32"
$system
[1] "i386, mingw32"
$status
[1] ""
$major
[1] "2"
$minor
[1] "10.1"
$year
[1] "2009"
$month
[1] "12"
$day
[1] "14"
$`svn rev`
[1] "50720"
$language
[1] "R"
$version.string
[1] "R version 2.10.1 (2009-12-14)"
Paul Rustomji
CSIRO Land and Water (Lucas Heights, NSW)
More information about the R-help
mailing list