[R] source output differs from console output
graham lawrence
forporphyry at hotmail.com
Sat Oct 26 01:05:18 CEST 2002
Dear R-help,
I would like to be able to run the following code sequence as a source
routine.
If I paste it into R via the clipboard it works as expected, but if I source
the code instead then the last 3 statements fail.
I've also tried writing to the file in place of the sink sequence, but that
also hits a snag. R 1.6, w98e2, dfr is a data frame containing the content
of Julian Faraway's gala data frame. I append the console log and 3 outputs
to the file.
Thanks for your help.
qnum<-""
if(given[1]!="NA")qnum<-paste("\n",given[1],".",sep = "")
xfr<-dfr
if(given[2]!="NA")
{
x<-as.numeric(unlist(strsplit(given[2],",")))
xfr<-cbind(dfr[,x])
}
varlst<-names(xfr)
mr<-lm(eval(parse(text=paste(varlst[1],"~",paste(varlst[-1],collapse="+")))),
data=xfr)
write(qnum,"math.txt",append = TRUE)
sink("math.txt",append = TRUE)
summary(mr)
sink()
The console log was as follows
>given
[1] "1" "1,3,5,7"
>qnum<-""
>if(given[1]!="NA")qnum<-paste("\n",given[1],".",sep = "")
>xfr<-gala
>if(given[2]!="NA")
+ {
+ x<-as.numeric(unlist(strsplit(given[2],",")))
+ xfr<-cbind(gala[,x])
+ }
>varlst<-names(xfr)
>mr<-lm(eval(parse(text=paste(varlst[1],"~",paste(varlst[-1],collapse="+")))),
>data=xfr)
>write(qnum,"math.txt",append = TRUE)
>sink("math.txt",append = TRUE)
>summary(mr)
>sink()
>write("now i run it as a source via mrfit.R","math.txt",append=TRUE)
>source("../sources/mrfit.R")
>write("now i run it with a write statement instead of the sink
>sequence","math.txt",append=TRUE)
>qnum<-""
>if(given[1]!="NA")qnum<-paste("\n",given[1],".",sep = "")
>xfr<-dfr
>if(given[2]!="NA")
+ {
+ x<-as.numeric(unlist(strsplit(given[2],",")))
+ xfr<-cbind(dfr[,x])
+ }
>varlst<-names(xfr)
>mr<-lm(eval(parse(text=paste(varlst[1],"~",paste(varlst[-1],collapse="+")))),
>data=xfr)
>write(qnum,"math.txt",append = TRUE)
>write(summary(mr),"math.txt",append = TRUE)
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 not yet handled by cat
>l<-summary(mr)
>write(l,"math.txt",append = TRUE)
Error in cat(list(...), file, sep, fill, labels, append) :
argument 1 not yet handled by cat
>l
Call:
lm(formula = eval(parse(text = paste(varlst[1], "~", paste(varlst[-1],
collapse = "+")))), data = xfr)
Residuals:
Min 1Q Median 3Q Max
-103.66 -53.31 -35.18 23.30 305.12
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 62.15560 22.98119 2.705 0.011901 *
Area 0.08465 0.02072 4.085 0.000375 ***
Nearest 0.37841 1.24235 0.305 0.763101
Adjacent -0.01104 0.02072 -0.533 0.598893
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 94.45 on 26 degrees of freedom
Multiple R-Squared: 0.3914, Adjusted R-squared: 0.3212
F-statistic: 5.573 on 3 and 26 DF, p-value: 0.004334
The 3 outputs to the file math.txt follow
1.
Call:
lm(formula = eval(parse(text = paste(varlst[1], "~", paste(varlst[-1],
collapse = "+")))), data = xfr)
Residuals:
Min 1Q Median 3Q Max
-103.66 -53.31 -35.18 23.30 305.12
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 62.15560 22.98119 2.705 0.011901 *
Area 0.08465 0.02072 4.085 0.000375 ***
Nearest 0.37841 1.24235 0.305 0.763101
Adjacent -0.01104 0.02072 -0.533 0.598893
---
Signif. codes: 0 `***' 0.001 `**' 0.01 `*' 0.05 `.' 0.1 ` ' 1
Residual standard error: 94.45 on 26 degrees of freedom
Multiple R-Squared: 0.3914, Adjusted R-squared: 0.3212
F-statistic: 5.573 on 3 and 26 DF, p-value: 0.004334
now i run it as a source via mrfit.R
1.
now i run it with a write statement instead of the sink sequence
1.
_________________________________________________________________
Internet access plans that fit your lifestyle -- join MSN.
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list