Skip to content

Commit

Permalink
try to fix R check error for old R version
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Nov 24, 2024
1 parent 1c316a3 commit 7285be7
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions R/raster-magick.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ makeContext.ggalign_raster_magick <- function(x) {

# Track current device
old_dev <- grDevices::dev.cur()

# Reset current device upon function exit
on.exit(grDevices::dev.set(old_dev), add = TRUE)
on.exit(grid::popViewport(), add = TRUE)
Expand All @@ -156,13 +157,16 @@ makeContext.ggalign_raster_magick <- function(x) {
bg = NA_character_, res = res,
clip = FALSE, antialias = FALSE
)

# reset viewport width and height
vp2 <- vp
vp2$x <- unit(0.5, "npc")
vp2$y <- unit(0.5, "npc")
vp2$just <- "center"
vp2$width <- unit(1, "npc")
vp2$height <- unit(1, "npc")
vp2 <- grid::editViewport(
vp,
x = unit(0.5, "npc"),
y = unit(0.5, "npc"),
just = "center",
width = unit(1, "npc"),
height = unit(1, "npc")
)
grid::pushViewport(vp2)
grid::grid.draw(x)
grid::popViewport()
Expand All @@ -182,6 +186,6 @@ makeContext.ggalign_raster_magick <- function(x) {
default.units = "npc",
just = "center",
interpolate = interpolate,
vp = vp
vp = .subset2(x, "vp")
)
}

0 comments on commit 7285be7

Please sign in to comment.