tags:

views:

243

answers:

4

I have installed rapache and i am trying to fit a linear model inside the R script file. I have configured the RFileHandler in the http.conf. When i am trying to invoke the summary(model) it is giving me a segment fault error ( i see this in the apache log file). I am guessing that it is trying to print to the console and that is why it is failing.

Has any one encountered a similar problem with R and rapache? I am relatively new to R and summary is doing a lot of things that are not directly exposed as functions so i am hoping i could get it to work

Here is my r script

mydata<- read.table("/home/user/test.csv",header=TRUE,sep=",")
fit<- lm(y~x1+x2+x3,data=mydata)
setContentType("text/html")
cat('<HTML><BODY>')
cat(summary(fit)$adj.r.squared)
cat('</BODY></HTML>\n')
DONE

if i replace

    cat(summary(fit)$adj.r.squared)

with this

    cat(coef(fit))

it is working!

Thanks Bharani

+1  A: 

Did you consider contacting the rapache Google Group as the rapache home page suggests? You may find more experienced reader there than here.

Dirk Eddelbuettel
Thanks - just posted in the rapache group
Bharani
+1  A: 

I have tested the following example and cat(summary(fit)$adj.r.squared) works in my (default) setup (latest rapache 1.1.8 and R 2.9.2 under Ubuntu 9.04)

ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2,10,20, labels=c("Ctl","Trt"))
weight <- c(ctl, trt)
fit <- lm(weight ~ group - 1) # omitting intercept
setContentType("text/html")
cat('<HTML><BODY>')
cat(summary(fit)$adj.r.squared)
cat('</BODY></HTML>\n')
DONE
rcs
Did you have to configure R with lapack? bcos with out that it failed the first time and then i did configure with lapack and it started working - just that it is failing when i call summary
Bharani
I have the same version of both R and rapache but on RHE 5.1
Bharani
I didn't compile R, just rapache. I'm using the R Ubuntu packages from CRAN (cran.r-project.org/bin/linux/…). BTW, there are also Red Hat packages.
rcs
A: 

Just found out that it is not with rapache. It is failing in R itself

 *** caught segfault ***
 address (nil), cause 'memory not mapped'

 Traceback:
  1: .Call("La_chol2inv", x, size, PACKAGE = "base")
  2: chol2inv(Qr$qr[p1, p1, drop = FALSE])
  3: summary.lm(fit)
  4: summary(fit)
  5: cat(summary(fit)$adj.r.squared)

 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace

not sure what that means though

-Bharani

Bharani
Hmm, curious. The "memory not mapped" error means that your code is reading from or writing to memory that it doesn't own.
rcs
A: 

I finally figured out the problem. Reading the discussion i wrongly libRlapck.so to lapack.so. Looks like that was causing problems. Did a clean install of R again and then modified apache to explicity load the libraries then it all worked Thanks - Bharani

Bharani