[R] running a .r script and saving the output to a file

Andrej Kastrin andrej.kastrin at gmail.com
Mon Jul 27 07:38:37 CEST 2009


Check out: http://akastrin.wordpress.com/category/r/

David Riebel wrote:
> Hello,
> 
> I am running R under Ubuntu 8.04.  I am trying to do numerous linear
> fits to various subsets of my data set.  I am having trouble convincing
> R to send the output from these fits to text files from within a script.
> When I run my script, all the plots are created as postscript files in
> the correct directory, and text files appear with the correct names for
> all the summaries of the fits.  However, all of these files are blank!
> If I copy/paste the "sink" commands from my script manually into the
> command line, the files are created correctly, but if the same commands
> are executed from within my script, no output is generated.
> 
> The output section of my script, which correctly creates the plots I
> want, but not the text, is:
> 
> x_seq1_fit=lm(xagb$X5mag[x_seq1_filt]~x1per)
> x_seq2_fit=lm(xagb$X5mag[x_seq2_filt]~x2per)
> 
> setwd("/home/driebel/sage/output/pl_fits/R/5mag/chem")
> postscript(file="x_seq1_fit.ps")
> plot(x1per,xagb$X5mag[x_seq1_filt],ylim=c(13,7))
> abline(x_seq1_fit,col="red")
> dev.off()
> postscript(file="x_seq1_resid.ps")
> plot(x1per,x_seq1_fit$res)
> abline(h=0,col="red")
> dev.off()
> 
> postscript(file="x_seq2_fit.ps")
> plot(x2per,xagb$X5mag[x_seq2_filt],ylim=c(13,7))
> abline(x_seq2_fit,col="red")
> dev.off()
> postscript(file="x_seq2_resid.ps")
> plot(x2per,x_seq2_fit$res)
> abline(h=0,col="red")
> dev.off()
> 
> sink(file="x_seq2_fit.dat")
> summary(x_seq2_fit)
> sink()
> sink(file="x_seq1_fit.dat")
> summary(x_seq1_fit)
> sink()
> 
> 
> Is there something else one must do with "sink" from within a script?
> Thanks for your help,
> 
> Dave
>




More information about the R-help mailing list