Hello, I want to run the following commands as a script(.r or .bat) and save the output in an external file through Windows OS. data<-read.csv(file="wgatever.csv", head=TRUE, sep=",") summary(data$SQFT) hist(data$STAMP) hist(data$STAMP, col='blue') hist(data$SHIP, col='blue') How could I do that? I have a great problem using the sink() function because it produces empty file. Please help! Gagan [[alternative HTML version deleted]]
David Winsemius
2009-Apr-09 17:27 UTC
[R] running a .r script and saving the output to a file
If you just entered sink(), it would turn *off* sink-ing. You need to tell R where to write the output that would otherwise go to the console. (Or if you did something like that then you need to tell us exactly what you did try.) ?sink # e.g. sink(file="... /test.txt") with correct path substituted for ... ?source And perhaps read up on submitting batch jobs from the Windows command line. See Appendix B of: http://cran.r-project.org/doc/manuals/R-intro.pdf -- David Winsemius On Apr 9, 2009, at 12:46 PM, Gagan Pabla wrote:> Hello, > > I want to run the following commands as a script(.r or .bat) and > save the > output in an external file through Windows OS. > > data<-read.csv(file="wgatever.csv", head=TRUE, sep=",") > > summary(data$SQFT) > > hist(data$STAMP) > > hist(data$STAMP, col='blue') > > hist(data$SHIP, col='blue') > > > > How could I do that? I have a great problem using the sink() function > because it produces empty file. Please help! > > Gagan > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
I first I saved the following commands in a whatever.r file. data<-read.csv(file="whatever.csv", head=TRUE, sep=",") summary(data$SQFT) hist(data$STAMP) hist(data$STAMP, col='blue') hist(data$SHIP, col='blue') then I clicked File Menu-> source and chose whatever.r, it runs the commands and produces the histograms and stuff. then I did sink("comm.docx") sink() It creates an empty file "comm.docx". Now my problem is that I want to run the commands in whatever.r file( this part is working ) and then save the output(has graphs hists etc) in a file. How do I do that ? Your help will be greatly appreciated!! Gagan [[alternative HTML version deleted]]
David Riebel
2009-Jul-26 20:47 UTC
[R] running a .r script and saving the output to a file
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
Andrej Kastrin
2009-Jul-27 05:38 UTC
[R] running a .r script and saving the output to a file
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 >