Sie sind auf Seite 1von 9

Chapter 9:

Exporting out of R
R output
✓ Different kinds of files!
➡ Text!
- Table data!
- R console output!
- Vector, matrix data!
➡ Graphics!
- PDF!
- Jpeg, bmp, tiff, png!
- Postscript!
- pictex!
- xfig
Text Files
✓ Function sink()!
➡ To send the output of R to a file, instead of the console, use function sink()!
- Usage: Type sink(file = , append = , split = …) at the command line. Parameter
append adds output to the file specified in file if TRUE, else it replaces the contents.
Parameter split if TRUE sends output to the file as well as the console, and if FALSE,
sends output only to the file.!
- Files gets created in the working directory!
- Example:
Text Files
✓ Function cat()!
➡ To create a text file with values, separated by a character [ex., comma, space etc]
function cat() may be used!
- Usage: Type cat(x, file = , sep = ,…) at the command line. Parameter sep specifies
the separating character!
- Files gets created in the working directory!
- Example:
Text Files
✓ Function write.table()!
➡ To create a data file from a matrix or data frame, use function write.table()!
- Usage: Type write.table(x, file = , append = , quote = , sep = ,dec =, row.names = ,
col.names = …) at the command line. Parameter append adds output to the file
specified in file if TRUE, else it replaces the contents. Parameter quote if TRUE
encloses any character values in “”. Parameter sep specifies the separating character
(examples: “,”, “ ”, “/t”). Parameter dec specifies the decimal character. Parameters
row.names/col.names specify whether row and column names are to be included. !
- Files gets created in the working directory!
- Example:
Exercise
Graphics
✓ Function jpeg()!
➡ To open a graphical device that will create a jpeg file from a plot, use function
jpeg()!
- Usage: Type jpeg(file = , width = , height = , units = , pointsize =, bg = , …) at the
command line. Parameter width/height define dimensions of the device [output file]
in units specified by parameter units. Parameter pointsize specifies default pointsize
of plotted text. Parameter bg specifies background color. !
- Files gets created in the working directory!
- Once complete, use function dev.off() [no parameters] to close the device!
- Example:
Graphics
✓ Function pdf()!
➡ To open a graphical device that will create a pdf file from a (series of) plot(s), use
function pdf()!
- Usage: Type pdf(file = , width = , height = , onefile = , family =, title = , paper = ,…)
at the command line. Parameter width/height define dimensions of the plot area in
inches. Parameter onefile specifies whether multiple plots need to be output in the
same file. Parameter family specifies font family. !
- Files gets created in the working directory!
- Once complete, use function dev.off() [no parameters] to close the device!
- Example:
Exercise

Das könnte Ihnen auch gefallen