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

jim holtman jholtman at gmail.com
Mon Jul 27 01:20:01 CEST 2009


You have to explicitly 'print' the output.  At the command line there
is an implicit 'print'.  Try:

sink(file="x_seq2_fit.dat")
print(summary(x_seq2_fit))
sink()
sink(file="x_seq1_fit.dat")
print(summary(x_seq1_fit))
sink()

On Sun, Jul 26, 2009 at 4:47 PM, David Riebel<driebel at pha.jhu.edu> 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
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list