Learn R Programming

ribiosUtils (version 1.5-6)

openFileDevice: Open a device as a file preparing for plotting in the file

Description

The function openFileDevice opens a device of the type specified by the file extension name. It such prepares the file for visualizing data. User must call dev.off once the writing (plotting) to the device is finished.

Usage

openFileDevice(filename, width = 7, height = 7, dpi = 300L, family)

Arguments

filename

Character, file name to be written to. The type of file is determined by the extension. See details below.

width

Number, figure width of the file in inch.

height

Number, figure height of the file in inch.

dpi

Number, resolution as “dots per inch”. For publication 300dpi is usually enough.

family

Font family name. Only applicable to PDF files

Value

Both functions are used for its side effect.

Details

closeFileDevice quietly closes the current device: it does not print the information of the next device.

The function openFileDevice calls extname to determine the file type to be drawn in. Currently supported types include PDF, tiff (tif), bmp, jpeg (jpeg). When the file type is not recognized, the PDF format is used as a fallback.

As an example, myplot.pdf will triggers openning a PDF device, newplot.png a PNG device, and oldplot.tiff a TIFF device, whereas myfile.abc will be openned as a PDF device.

For bitmap files like BMP, JPEG,PNG and TIFF, we use inch as the size unit in order to be compatible with PDF. And the resolution is always set to 300dpi.Furthermore, JPEG quality is set to 90 instead of the default value 75, and TIFF do not use any compression. These settings follow our practices for scientific publication while allowing generic post-precessing of figures.

See Also

extname for getting extension name of file. See pdf, png, jpeg, tiff and bmp for file formats.

Examples

Run this code
# NOT RUN {
if(interactive()) {
  tempfile1 <- paste(tempfile(), ".pdf", sep="")
  openFileDevice(tempfile1)
  plot(rnorm(100), rnorm(100))
  closeFileDevice()

  tempfile2 <- paste(tempfile(), ".png", sep="")
  openFileDevice(tempfile2, width=5, height=5)
  plot(rnorm(100), rnorm(100))
  closeFileDevice()
}

# }

Run the code above in your browser using DataLab