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

Description Usage Arguments Details Value Note Author(s) See Also Examples

View source: R/openFileDevice.R

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

1
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

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.

Value

Both functions are used for its side effect.

Note

After plotting, user should call dev.off to close the device in the file, otherwise the file can probably not be read.

Author(s)

Jitao David Zhang <jitao_david.zhang@roche.com>

See Also

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

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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()
}

ribiosUtils documentation built on March 13, 2020, 2:54 a.m.