dev_off_crop: Cropping Device

dev_off_cropR Documentation

Cropping Device

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

dev.off.crop(file = NULL, warn = TRUE, which = dev.cur(),
             post.cmd = "1>/dev/null 2>&1", ...)

Arguments

file

output file name including extension.

warn

logical indicating whether warnings shall be given in case an unsupported operating system is used or the underlying Unix tools are not found.

which

see dev.off().

post.cmd

character string appended to the main underlying commands (epstool, pdfcrop, mogrify).

...

additional arguments passed to the underlying system().

Details

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

Value

invisible().

Author(s)

Marius Hofert

See Also

dev.off() for closing a device.

Examples

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

## PDF
pdf(file = (file <- "crop.pdf"))
plot(1:10, 10:1, xlab = "x", ylab = "y")
dev.off.crop(file = file)
stopifnot(file.remove("crop.pdf")) # clean-up

## PNG with white background
png(filename = (file <- "crop.png"))
plot(1:10, 10:1, xlab = "x", ylab = "y")
dev.off.crop(file = file)
stopifnot(file.remove("crop.png")) # clean-up

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

crop documentation built on June 22, 2025, 3:01 p.m.

Related to dev_off_crop in crop...