Working with output
Instead of copying R output and pasting it into a text file, the function sink() allows you to send R output directly into an external text file. The first argument of sink() specifies the directory and file where your output will be saved. A second argument, split, is used to control whether the output appears in the console window or not. If the split argument is TRUE, your output will be sent to an external file as well as displayed in the R console (set split to FALSE if you prefer your output not to be displayed in the console). You would use the sink() function before any analysis that you want directed to the output file. After running your analyses (one or multiple), the sink() function without any arguments interrupts the process, and subsequent analyses are not sent to the output.txt file.
> sink("C:/user/temp/output.txt", split=T) > lm(Invest~Institutions+Gov.Spend+Growth+Open.Market) > sink()
Working with graphs
To export R graphs to an external file, use the jpeg() function, in which you specify the directory and file (extension .jpg) where the R graph should be saved. As is the case with sink(), you would use the jpeg() function before creating the graph, and then use the dev.off() function to shut down the jpeg() function so subsequent graphs are not saved as external .jpeg files.
> jpeg("C:/user/temp/histogram.jpg") > layout(matrix(1:4, 2, 2)) > plot(results1) > dev.off()
Next: Further Help
Prev: Data Analysis
Up: Table of Contents