Skip to content

Commit e3877c4

Browse files
zorroozclaude
andcommitted
simplify: extract ._print_render helper shared by knit_print + pkgdown_print
knit_print.plotit and pkgdown_print.plotit had identical bodies (x <- ._sync_labels(x); ._render_plotit(x)). Extract into ._print_render. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a536ac9 commit e3877c4

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

R/output.R

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ S7::method(format, plotit_composite) <- function(x, ...) ""
4141
#' @exportS3Method pkgdown::pkgdown_print
4242
pkgdown_print.plotit <- function(x, visible = TRUE) {
4343
if (!visible) return(invisible())
44-
x <- ._sync_labels(x)
45-
._render_plotit(x)
44+
._print_render(x)
4645
}
4746

4847
#' @exportS3Method pkgdown::pkgdown_print
@@ -106,12 +105,20 @@ print.plotit <- function(x, ...) {
106105
# ---- knit_print ----
107106
# S3 methods for knitr to capture plotit plots in vignettes / R Markdown.
108107
# Renders the underlying ggplot to knitr's active device.
109-
#' @exportS3Method knitr::knit_print
110-
knit_print.plotit <- function(x, ...) {
108+
109+
# Shared knit_print / pkgdown_print path: sync labels, render, suppress text.
110+
#' @noRd
111+
#' @keywords internal
112+
._print_render <- function(x) {
111113
x <- ._sync_labels(x)
112114
._render_plotit(x)
113115
}
114116

117+
#' @exportS3Method knitr::knit_print
118+
knit_print.plotit <- function(x, ...) {
119+
._print_render(x)
120+
}
121+
115122
#' @exportS3Method knitr::knit_print
116123
knit_print.plotit_composite <- function(x, ...) {
117124
x@gg <- ._apply_annotations(x)

0 commit comments

Comments
 (0)