Skip to content

Commit 59820ab

Browse files
committed
Fix issue #68
1 parent f415235 commit 59820ab

1 file changed

Lines changed: 30 additions & 24 deletions

File tree

R/save_ipeaplot.R

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,12 @@ save_ipeaplot <- function(
4444
quiet = TRUE,
4545
...
4646
) {
47-
if (!inherits(gplot, "ggplot"))
47+
if (!inherits(gplot, "ggplot")) {
4848
stop("gplot must be a ggplot2 object.", call. = FALSE)
49-
if (
50-
!is.character(file.name) ||
51-
length(file.name) != 1L ||
52-
nchar(file.name) == 0L
53-
)
49+
}
50+
if (!is.character(file.name) || length(file.name) != 1L || nchar(file.name) == 0L) {
5451
stop("file.name must be a non-empty string.", call. = FALSE)
52+
}
5553

5654
units <- match.arg(units)
5755

@@ -68,33 +66,43 @@ save_ipeaplot <- function(
6866
height <- height / 25.4
6967
message(sprintf(
7068
"Dimensions too large in 'in'; interpreting as mm -> width=%.2f in, height=%.2f in.",
71-
width,
72-
height
69+
width, height
7370
))
7471
}
7572

7673
base_name <- sub("\\.[^.]+$", "", file.name)
77-
if (include_date)
74+
if (include_date) {
7875
base_name <- paste0(base_name, "_", format(Sys.Date(), date_format))
76+
}
77+
78+
ext <- function(fmt) {
79+
switch(fmt,
80+
eps = ".eps",
81+
jpg = ".jpg",
82+
pdf = ".pdf",
83+
png = ".png",
84+
svg = ".svg"
85+
)
86+
}
7987

80-
ext <- function(fmt)
81-
switch(fmt, eps = ".eps", jpg = ".jpg", pdf = ".pdf", png = ".png", svg = ".svg")
88+
# ---------------------------------------------------------------------------
89+
# CORREÇÃO: evitar segfault do ragg no macOS em ambientes CI (GitHub Actions)
90+
# - Se estiver em CI + macOS, cai para device base png/jpeg.
91+
# - Permite forçar desligar via env var: IPEAPLOT_DISABLE_RAGG=1/true/yes
92+
# ---------------------------------------------------------------------------
93+
is_ci <- identical(Sys.getenv("GITHUB_ACTIONS"), "true") || identical(Sys.getenv("CI"), "true")
94+
is_macos <- identical(Sys.info()[["sysname"]], "Darwin")
95+
ragg_disabled <- tolower(Sys.getenv("IPEAPLOT_DISABLE_RAGG")) %in% c("1", "true", "yes")
96+
use_ragg_eff <- isTRUE(use_ragg) && !ragg_disabled && !(is_ci && is_macos)
8297

8398
get_device <- function(fmt) {
84-
if (
85-
fmt %in%
86-
c("png", "jpg") &&
87-
use_ragg &&
88-
requireNamespace("ragg", quietly = TRUE)
89-
) {
99+
if (fmt %in% c("png", "jpg") && use_ragg_eff && requireNamespace("ragg", quietly = TRUE)) {
90100
return(if (fmt == "png") ragg::agg_png else ragg::agg_jpeg)
91101
}
92102
if (fmt == "png") return("png")
93103
if (fmt == "jpg") return("jpeg")
94-
if (fmt == "pdf")
95-
return(if (use_cairo) grDevices::cairo_pdf else grDevices::pdf)
96-
if (fmt == "eps")
97-
return(if (use_cairo) grDevices::cairo_ps else grDevices::postscript)
104+
if (fmt == "pdf") return(if (use_cairo) grDevices::cairo_pdf else grDevices::pdf)
105+
if (fmt == "eps") return(if (use_cairo) grDevices::cairo_ps else grDevices::postscript)
98106
if (fmt == "svg") {
99107
# Usa svglite se disponível; senão cai para o device base (grDevices::svg via "svg")
100108
if (requireNamespace("svglite", quietly = TRUE)) return(svglite::svglite)
@@ -151,9 +159,7 @@ save_ipeaplot <- function(
151159
# - Em pdf()/postscript(): useDingbats = FALSE (evita fontes dingbat)
152160
# - Em todos vetoriais (inclui Cairo): fallback_resolution para rasterizacao
153161
if (fmt %in% c("pdf", "eps", "svg")) {
154-
if (
155-
identical(dev, grDevices::pdf) || identical(dev, grDevices::postscript)
156-
) {
162+
if (identical(dev, grDevices::pdf) || identical(dev, grDevices::postscript)) {
157163
gargs$useDingbats <- FALSE
158164
}
159165
gargs$fallback_resolution <- dpi

0 commit comments

Comments
 (0)