dev_off_crop: Cropping Device

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

Description

dev.off.crop() calls dev.off() to close the plotting device and then crops the produced graphic. This works on Unix-like systems if the right underlying Unix tools are installed and found (see below).

Usage

1

Arguments

file

An output file name including extension.

warn

A logical indicating whether warnings shall be given in case the wrong operating system is used or the underlying Unix tools are not available.

...

Additional arguments passed to dev.off().

Details

Supported file extensions are .ps (epstool), .eps (epstool), .pdf (pdfcrop), .png (mogrify) if the underlying tools (given in parentheses) are installed and found. If they are not installed or found or if the wrong operating system is used, simply dev.off() is called (and thus no cropping is done).

Value

invisible().

Author(s)

Marius Hofert

See Also

dev.off() for closing a device.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## Example data
x <- 1:10
y <- rev(x)

## PS
postscript(file=(file <- "crop.ps"))
plot(x, y, xlab="x", ylab="y")
dev.off.crop(file=file)

## EPS
setEPS() # or use onefile=FALSE, horizontal=FALSE, paper="special" in postscript()
postscript(file=(file <- "crop.eps"))
plot(x, y, xlab="x", ylab="y")
dev.off.crop(file=file)

## PDF
pdf(file=(file <- "crop.pdf"))
plot(x, y, xlab="x", ylab="y")
dev.off.crop(file=file)

## PNG with white background
png(filename=(file <- "crop.png"))
plot(x, y, xlab="x", ylab="y")
dev.off.crop(file=file)

## PNG with transparent background
## Not doable by the underlying 'mogrify' (only cropped vertically, not horizontally)
if(FALSE) {
    png(filename=(file <- "crop.png"), bg="transparent")
    plot(x, y, xlab="x", ylab="y")
    dev.off.crop(file=file)
}

Example output

Warning messages:
1: In system(paste("command -v", command, ">/dev/null 2>&1")) :
  error in running command
2: In dev.off.crop(file = file) :
  Command 'epstool' for cropping PS files not found; no cropping is done.
Warning messages:
1: In system(paste("command -v", command, ">/dev/null 2>&1")) :
  error in running command
2: In dev.off.crop(file = file) :
  Command 'epstool' for cropping PS files not found; no cropping is done.
Warning messages:
1: In system(paste("command -v", command, ">/dev/null 2>&1")) :
  error in running command
2: In dev.off.crop(file = file) :
  Command 'mogrify' for cropping PNG files not found; no cropping is done.

crop documentation built on May 2, 2019, 6:54 a.m.

Related to dev_off_crop in crop...