Output

Statistical procedures

By way of standard, all output is simply sent to the screen (that is, to the R console), and to save it, you can just highlight the parts of the output you are interested in, copy it to the clipboard and paste it into a word processor.

There are packages to obtain output formatted for different word processing packages such as MS Word or LaTeX. Perhaps I will say more about this at a later stage.

Sending output to a file

Output is sent to a file (instead of, or in addition to, being sent to the screen), with the following command

sink("name-of-output-file", append=FALSE/TRUE, split=FALSE/TRUE)

The append option decides whether the output is appended to an existing file or whether the file is overwritten. The split option decides whether the output is sent to the file only (split=FALSE) or additionally to the screen.

To stop output being written to the file, just type

sink()

Graphs

Normally, graphs or plots are displayed in a new window. You can save the plot to a 'postscript' or a 'metafile' file by clicking with the right mouse button into the plot and selecting the appropriate action. You may also select "print" and send the plot to a PDF file, if your computer's set-up permits.

Additional formats are available by changing the 'device' of your output (which normally is the screen). That is, the output will be sent to a file in the format you have specified – but not to your screen. To change the device, you simply type one of the following commands (a few further devices are available a list of which you can obtain by typing 'help(Devices)'):

pdf("filename.pdf") output written to PDF file
jpeg("filename.jpg") output written to JPEG file
pictex("filename.pic") output written to LaTeX/PicTeX file
bmp("filename.bmp") output written to bitmap file
postscript("filename.ps") output written to postscript file

The output is sent to files which you will find in your working directory (or wherever R chooses, if no working directory has been defined), but it will be written only after you type the command dev.off(). Of course, you may add a path to the filename for sake of clarity. Note that, on the other hand, you can use the device commands without filenames (i.e., you may write simply pdf() or whichever command you choose). In this case, the first plot will be written to file Rplot001.xxx (with xxx being replaced by the appropriate extension, for instance, .jpg in the case of JPEG files), the second to file Rplot002.xxx, and so on. If the device has been set off and is then set on again, counting starts anew; in other words, your old file(s) will be written over if you have not renamed them.

© W. Ludwig-Mayerhofer, IGRW | Last update: 09 Dec 2016