New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added with_device and device_dev fns #37
Closed
Closed
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a0575cd
added with_device and device_dev fns
1dd9ac8
added missing with_png
b3ce3ff
fixed antialias arg problem with with_png, with_jpeg; improved examples
53ebdb4
updated roxygen style to match rest of package
479156d
other raster plots also need antialias fix
ff182cc
added tests for with_*device* fns
aee7d37
more contexts for tests
d68e1ac
removed previously missed @importFrom
2247aff
replaced @inheritParams with manual @params for pdf, postscript, to a…
2dfd5e8
better @describeIn for with_cairo_* fns
17921fd
roxy
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# Internal *_dev functions ------------------------------------------------ | ||
|
||
#' @importFrom grDevices dev.cur | ||
#' @include wrap.R | ||
NULL | ||
|
||
#' @importFrom grDevices bmp | ||
bmp_dev <- wrap(bmp, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices cairo_pdf | ||
cairo_pdf_dev <- wrap(cairo_pdf, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices cairo_ps | ||
cairo_ps_dev <- wrap(cairo_ps, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices jpeg | ||
jpeg_dev <- wrap(jpeg, antialias <- match.arg(antialias), dev.cur()) | ||
|
||
#' @importFrom grDevices pdf | ||
pdf_dev <- wrap(pdf, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices png | ||
png_dev <- wrap(png, antialias <- match.arg(antialias), dev.cur()) | ||
|
||
#' @importFrom grDevices postscript | ||
postscript_dev <- wrap(postscript, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices svg | ||
svg_dev <- wrap(svg, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices tiff | ||
tiff_dev <- wrap(tiff, NULL, dev.cur()) | ||
|
||
#' @importFrom grDevices xfig | ||
xfig_dev <- wrap(xfig, NULL, dev.cur()) | ||
|
||
|
||
# User-level with_* fns --------------------------------------------------- | ||
|
||
#' Graphics devices | ||
#' | ||
#' Temporarily use a graphics device. | ||
#' | ||
#' @template with | ||
#' @param new \code{[named character]}\cr New graphics device | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please double-check documentation of this argument. |
||
#' @seealso \code{\link[grDevices]{Devices}} | ||
#' @examples | ||
#' # dimensions are in inches | ||
#' with_pdf( | ||
#' c(file = file.path(tempdir(), "test.pdf"), width = 7, height = 5), | ||
#' plot(runif(5)) | ||
#' ) | ||
#' | ||
#' # dimensions are in pixels | ||
#' with_png( | ||
#' c(file = file.path(tempdir(), "test.png"), width = 800, height = 600), | ||
#' plot(runif(5)) | ||
#' ) | ||
#' @aliases with_dev with_device | ||
#' @importFrom grDevices dev.off | ||
#' @export | ||
with_bmp <- with_(bmp_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_cairo_pdf <- with_(cairo_pdf_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_cairo_ps <- with_(cairo_ps_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_jpeg <- with_(jpeg_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_pdf <- with_(pdf_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_png <- with_(png_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_postscript <- with_(postscript_dev, dev.off) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The names "with_cairo_ps()" and "with_postscript()" look inconsistent to me. |
||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_svg <- with_(svg_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_tiff <- with_(tiff_dev, dev.off) | ||
|
||
#' @rdname with_bmp | ||
#' @export | ||
with_xfig <- with_(xfig_dev, dev.off) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
% Generated by roxygen2 (4.1.1): do not edit by hand | ||
% Please edit documentation in R/devices.R | ||
\name{with_bmp} | ||
\alias{with_bmp} | ||
\alias{with_cairo_pdf} | ||
\alias{with_cairo_ps} | ||
\alias{with_dev} | ||
\alias{with_device} | ||
\alias{with_jpeg} | ||
\alias{with_pdf} | ||
\alias{with_png} | ||
\alias{with_postscript} | ||
\alias{with_svg} | ||
\alias{with_tiff} | ||
\alias{with_xfig} | ||
\title{Graphics devices} | ||
\usage{ | ||
with_bmp(new, code, width = 480, height = 480, units = "px", | ||
pointsize = 12, bg = "white", res = NA, family = "sans", | ||
restoreConsole = TRUE, type = c("windows", "cairo"), | ||
antialias = c("default", "none", "cleartype", "gray", "subpixel")) | ||
|
||
with_cairo_pdf(new, code, width = 7, height = 7, pointsize = 12, | ||
onefile = FALSE, family = "sans", bg = "white", | ||
antialias = c("default", "none", "gray", "subpixel"), | ||
fallback_resolution = 300) | ||
|
||
with_cairo_ps(new, code, width = 7, height = 7, pointsize = 12, | ||
onefile = FALSE, family = "sans", bg = "white", | ||
antialias = c("default", "none", "gray", "subpixel"), | ||
fallback_resolution = 300) | ||
|
||
with_jpeg(new, code, width = 480, height = 480, units = "px", | ||
pointsize = 12, quality = 75, bg = "white", res = NA, | ||
family = "sans", restoreConsole = TRUE, type = c("windows", "cairo"), | ||
antialias = c("default", "none", "cleartype", "gray", "subpixel")) | ||
|
||
with_pdf(new, code, width, height, onefile, family, title, fonts, version, | ||
paper, encoding, bg, fg, pointsize, pagecentre, colormodel, useDingbats, | ||
useKerning, fillOddEven, compress) | ||
|
||
with_png(new, code, width = 480, height = 480, units = "px", | ||
pointsize = 12, bg = "white", res = NA, family = "sans", | ||
restoreConsole = TRUE, type = c("windows", "cairo", "cairo-png"), | ||
antialias = c("default", "none", "cleartype", "gray", "subpixel")) | ||
|
||
with_postscript(new, code, onefile, family, title, fonts, encoding, bg, fg, | ||
width, height, horizontal, pointsize, paper, pagecentre, print.it, command, | ||
colormodel, useKerning, fillOddEven) | ||
|
||
with_svg(new, code, width = 7, height = 7, pointsize = 12, | ||
onefile = FALSE, family = "sans", bg = "white", | ||
antialias = c("default", "none", "gray", "subpixel")) | ||
|
||
with_tiff(new, code, width = 480, height = 480, units = "px", | ||
pointsize = 12, compression = c("none", "rle", "lzw", "jpeg", "zip", | ||
"lzw+p", "zip+p"), bg = "white", res = NA, family = "sans", | ||
restoreConsole = TRUE, type = c("windows", "cairo"), | ||
antialias = c("default", "none", "cleartype", "gray", "subpixel")) | ||
|
||
with_xfig(new, code, onefile = FALSE, encoding = "none", | ||
paper = "default", horizontal = TRUE, width = 0, height = 0, | ||
family = "Helvetica", pointsize = 12, bg = "transparent", | ||
fg = "black", pagecentre = TRUE, defaultfont = FALSE, | ||
textspecial = FALSE) | ||
} | ||
\arguments{ | ||
\item{new}{\code{[named character]}\cr New graphics device} | ||
|
||
\item{code}{\code{[any]}\cr Code to execute in the temporary environment} | ||
} | ||
\value{ | ||
\code{[any]}\cr The results of the evaluation of the \code{code} | ||
argument. | ||
} | ||
\description{ | ||
Temporarily use a graphics device. | ||
} | ||
\examples{ | ||
# dimensions are in inches | ||
with_pdf( | ||
c(file = file.path(tempdir(), "test.pdf"), width = 7, height = 5), | ||
plot(runif(5)) | ||
) | ||
|
||
# dimensions are in pixels | ||
with_png( | ||
c(file = file.path(tempdir(), "test.png"), width = 800, height = 600), | ||
plot(runif(5)) | ||
) | ||
} | ||
\seealso{ | ||
\code{\link{withr}} for examples | ||
|
||
\code{\link[grDevices]{Devices}} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please update your roxygen2 installation?