This example works fine for me, see session below. Tested on J802, linux64, R 3.02.
What versions of R and J are you running, and what OS? Chris load '~addons/stats/r/rserve.ijs' RserveExample=: 3 : 0 rdcmd_rserve_ 'x<-c(1,2,3,4,5)' (1!:2) 2 rdcmd_rserve_ 'y<-c(8,21,31,38,50)' (1!:2) 2 rdcmd_rserve_ 'modelfit<-glm(y~x, family=gaussian(link=identity))' (1!:2) 2 if. y do. rdget_rserve_ 'capture.output(summary(modelfit))' (1!:2) 2 else. rdget_rserve_ 'capture.output(residuals(modelfit))' (1!:2) 2 end. ) RserveExample 0 x<-c(1,2,3,4,5) y<-c(8,21,31,38,50) modelfit<-glm(y~x, family=gaussian(link=identity)) capture.output(residuals(modelfit)) +-------------------------+-------------------------+ | 1 2 3 4 5 |-1.4 1.5 1.4 -1.7 0.2 | +-------------------------+-------------------------+ RserveExample 1 x<-c(1,2,3,4,5) y<-c(8,21,31,38,50) modelfit<-glm(y~x, family=gaussian(link=identity)) capture.output(summary(modelfit)) ++-----+--------------------------------------------------------++-------------------... ||Call:|glm(formula = y ~ x, family = gaussian(link = identity))||Deviance Residuals:... ++-----+--------------------------------------------------------++-------------------... On Mon, Jul 28, 2014 at 6:40 AM, <[email protected]> wrote: > Here's an example: > > We define a function to run a simple GLM in R. > > > RserveExample=: 3 : 0 > rdcmd_rserve_ 'x<-c(1,2,3,4,5)' (1!:2) 2 > rdcmd_rserve_ 'y<-c(8,21,31,38,50)' (1!:2) 2 > rdcmd_rserve_ 'modelfit<-glm(y~x, family=gaussian(link=identity))' (1!:2) 2 > if. y do. rdget_rserve_ 'capture.output(summary(modelfit))' (1!:2) 2 > else. rdget_rserve_ 'capture.output(residuals(modelfit))' (1!:2) 2 > end. > ) > > If we run this with y=0 everything is fine. It prints each R command to > screen (so we can copy and paste to R if it fails to run in J), and the > result is a expected (here opened so as to look better in an email). > > >RserveExample 0 > > x<-c(1,2,3,4,5) > y<-c(8,21,31,38,50) > modelfit<-glm(y~x, family=gaussian(link=identity)) > capture.output(residuals(modelfit)) > 1 2 3 4 5 > -1.4 1.5 1.4 -1.7 0.2 > > But if we run it with y=1, so as to execute summary(modelfit) in R, it > fails: > > x<-c(1,2,3,4,5) > y<-c(8,21,31,38,50) > modelfit<-glm(y~x, family=gaussian(link=identity)) > capture.output(summary(modelfit)) > Status code: 127 > > If we copy and paste the lines to R, it works there: > > > x<-c(1,2,3,4,5) > > y<-c(8,21,31,38,50) > > modelfit<-glm(y~x, family=gaussian(link=identity)) > > capture.output(summary(modelfit)) > [1] "" > [2] "Call:" > [3] "glm(formula = y ~ x, family = gaussian(link = identity))" > [4] "" > [5] "Deviance Residuals: " > [6] " 1 2 3 4 5 " > [7] "-1.4 1.5 1.4 -1.7 0.2 " > [8] "" > [9] "Coefficients:" > [10] " Estimate Std. Error t value Pr(>|t|) " > [11] "(Intercept) -0.7000 1.8267 -0.383 0.727103 " > [12] "x 10.1000 0.5508 18.338 0.000354 ***" > [13] "---" > [14] "Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1" > [15] "" > [16] "(Dispersion parameter for gaussian family taken to be 3.033333)" > [17] "" > [18] " Null deviance: 1029.2 on 4 degrees of freedom" > [19] "Residual deviance: 9.1 on 3 degrees of freedom" > [20] "AIC: 23.184" > [21] "" > [22] "Number of Fisher Scoring iterations: 2" > [23] "" > > > > All the double quotes are because we used capture.output(), but they are > not the problem. > > Nor is summary() the problem per se. It works fine with some objects: > > rdcmd_rserve_ 'y<-rnorm(8)' > >rdget_rserve_ 'capture.output(summary(y))' > Min. 1st Qu. Median Mean 3rd Qu. Max. > -0.9317 -0.6148 -0.1200 -0.1164 0.2642 0.9486 > > So the problem seems to be with executing summary() on particular kinds of > R objects. > > Hope this gives some insight! > > Thanks, > > Richard Vaughan > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
