Skip to content

Commit 2a943da

Browse files
committed
doc: use agg_capture for man involving ragg
1 parent ea4a8bc commit 2a943da

File tree

7 files changed

+52
-103
lines changed

7 files changed

+52
-103
lines changed

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ importFrom(officer,table_width)
334334
importFrom(officer,to_html)
335335
importFrom(officer,to_rtf)
336336
importFrom(officer,to_wml)
337+
importFrom(ragg,agg_capture)
337338
importFrom(ragg,agg_png)
338339
importFrom(rlang,call_args)
339340
importFrom(rlang,enquo)

R/grid_grobs.R

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -98,48 +98,17 @@
9898
#' set_flextable_defaults(font.family = "Liberation Sans")
9999
#'
100100
#' ft <- flextable(head(mtcars))
101-
#'
102101
#' gr <- gen_grob(ft)
103-
#'
104-
#' png_f_1 <- tempfile(fileext = ".png")
105-
#' ragg::agg_png(
106-
#' filename = png_f_1, width = 4, height = 2,
107-
#' units = "in", res = 150)
108-
#' plot(gr)
109-
#' dev.off()
110-
#'
111-
#' png_f_2 <- tempfile(fileext = ".png")
112-
#' # get the size
113-
#' dims <- dim(gr)
114-
#' dims
115-
#' ragg::agg_png(
116-
#' filename = png_f_2, width = dims$width + .1,
117-
#' height = dims$height + .1, units = "in", res = 150
118-
#' )
102+
#' \dontshow{
103+
#' cap <- ragg::agg_capture(width = 7, height = 4, units = "in", res = 150)
104+
#' grDevices::dev.control("enable")
105+
#' }
119106
#' plot(gr)
107+
#' \dontshow{
108+
#' raster <- cap()
120109
#' dev.off()
121-
#'
122-
#'
123-
#' if (require("ggplot2")) {
124-
#' png_f_3 <- tempfile(fileext = ".png")
125-
#' z <- summarizor(iris, by = "Species")
126-
#' ft <- as_flextable(z, spread_first_col = TRUE)
127-
#' ft <- color(ft, color = "gray", part = "all")
128-
#' gg <- ggplot(data = iris, aes(Sepal.Length, Petal.Width)) +
129-
#' annotation_custom(
130-
#' gen_grob(ft, scaling = "full"),
131-
#' xmin = 4.5, xmax = 7.5, ymin = 0.25, ymax = 2.25) +
132-
#' geom_point() +
133-
#' theme_minimal()
134-
#' ragg::agg_png(
135-
#' filename = png_f_3, width = 7,
136-
#' height = 7, units = "in", res = 150
137-
#' )
138-
#' print(gg)
139-
#' dev.off()
110+
#' plot(as.raster(raster))
140111
#' }
141-
#'
142-
#'
143112
#' @family flextable print function
144113
#' @importFrom grid gTree
145114
gen_grob <- function(x,

R/patchwork.R

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,19 +128,20 @@
128128
#' ft <- align(ft, align = "right", part = "all")
129129
#' ft <- autofit(ft)
130130
#'
131-
#' tf <- tempfile(fileext = ".png")
132-
#' ragg::agg_png(
133-
#' filename = tf, width = 10,
134-
#' height = 5, units = "in", res = 150
135-
#' )
131+
#' \dontshow{
132+
#' cap <- ragg::agg_capture(width = 7, height = 6, units = "in", res = 150)
133+
#' grDevices::dev.control("enable")
134+
#' }
136135
#' print(
137136
#' wrap_flextable(ft, flex_body = TRUE, just = "right") +
138-
#' p +
139-
#' plot_layout(widths = c(1.1, 2))
137+
#' p + plot_layout(widths = c(1.1, 2))
140138
#' )
139+
#' \dontshow{
140+
#' raster <- cap()
141141
#' dev.off()
142-
#'
142+
#' plot(as.raster(raster))
143143
#' init_flextable_defaults()
144+
#' }
144145
#' @family flextable print function
145146
wrap_flextable <- function(
146147
x,

R/printers.R

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ save_as_rtf <- function(..., values = NULL, path, pr_section = NULL) {
10111011
#'
10121012
#' init_flextable_defaults()
10131013
#' @family flextable print function
1014-
#' @importFrom ragg agg_png
1014+
#' @importFrom ragg agg_png agg_capture
10151015
save_as_image <- function(x, path, expand = 10, res = 200, ...) {
10161016
if (!inherits(x, "flextable")) {
10171017
stop(sprintf("Function `%s` supports only flextable objects.", as.character(sys.call()[[1]])))
@@ -1077,13 +1077,17 @@ save_as_image <- function(x, path, expand = 10, res = 200, ...) {
10771077
#' set_flextable_defaults(font.family = "Liberation Sans")
10781078
#' ftab <- as_flextable(cars)
10791079
#'
1080-
#' tf <- tempfile(fileext = ".png")
1081-
#' agg_png(
1082-
#' filename = tf, width = 1.7, height = 3.26, unit = "in",
1083-
#' background = "transparent", res = 150
1084-
#' )
1080+
#' \dontshow{
1081+
#' cap <- ragg::agg_capture(width = 7, height = 6, units = "in", res = 150)
1082+
#' grDevices::dev.control("enable")
1083+
#' }
10851084
#' plot(ftab)
1085+
#' \dontshow{
1086+
#' raster <- cap()
10861087
#' dev.off()
1088+
#' plot(as.raster(raster))
1089+
#' init_flextable_defaults()
1090+
#' }
10871091
#' @family flextable print function
10881092
#' @importFrom grid grid.newpage grid.draw viewport pushViewport popViewport
10891093
plot.flextable <- function(x, ...) {

man/gen_grob.Rd

Lines changed: 7 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot.flextable.Rd

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/wrap_flextable.Rd

Lines changed: 9 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)