bug(install): `element_geom()` causes issues for macos w/ R 4.2
When trying to install ggplot2 v4.0.0 from CRAN for rstudio/shinycoreci (hard to make a min reprex), macos w/ R4.2 states:
2025-10-16T05:15:46.1158060Z * installing *source* package ‘ggplot2’ ...
2025-10-16T05:15:46.1762700Z ** package ‘ggplot2’ successfully unpacked and MD5 sums checked
2025-10-16T05:15:46.1875950Z staged installation is only possible with locking
2025-10-16T05:15:46.1876520Z ** using non-staged installation
2025-10-16T05:15:46.1983780Z ** R
2025-10-16T05:15:46.2151380Z ** data
2025-10-16T05:15:46.2384970Z *** moving datasets to lazyload DB
2025-10-16T05:15:46.2546800Z ** inst
2025-10-16T05:15:46.2711360Z ** byte-compile and prepare package for lazy loading
2025-10-16T05:15:46.2872170Z Error : <element_geom> object properties are invalid:
2025-10-16T05:15:46.2981310Z - @ink
2025-10-16T05:15:46.3089570Z - @paper
2025-10-16T05:15:46.3195950Z - @accent
2025-10-16T05:15:46.3310180Z - @colour
2025-10-16T05:15:46.3420000Z - @fill
I see that element_geom() is used to immediately create .default_element_geom object, but I don't see why the error is occurring. Any ideas as to why?
Related install output (full logs):
2025-10-16T05:15:33.2579110Z → Will download 13 CRAN packages (15.04 MB).
2025-10-16T05:15:33.2690950Z + crosstalk 1.2.2.9000 👷🏼♂️ ⬇ (416.15 kB)
2025-10-16T05:15:33.2792670Z + DT 0.34.0.9000 👷♀️ ⬇ (1.71 MB)
2025-10-16T05:15:33.2894250Z + farver 2.1.2 ⬇ (1.97 MB)
2025-10-16T05:15:33.2995990Z + ggplot2 4.0.0 👷🏾 ⬇ (3.81 MB)
2025-10-16T05:15:33.3037740Z + gtable 0.3.6 👷♂️ ⬇ (148.15 kB)
2025-10-16T05:15:33.3045520Z + htmlwidgets 1.6.4 → 1.6.4.9000 👷🏼 ⬇ (2.92 MB)
2025-10-16T05:15:33.3126160Z + isoband 0.2.7 ⬇ (1.87 MB)
2025-10-16T05:15:33.3129130Z + labeling 0.4.3 ⬇ (61.31 kB)
2025-10-16T05:15:33.3139280Z + lazyeval 0.2.2 ⬇ (159.75 kB)
2025-10-16T05:15:33.3140960Z + RColorBrewer 1.1-3 ⬇ (52.94 kB)
2025-10-16T05:15:33.3142110Z + S7 0.1.1 ⬇ (289.42 kB)
2025-10-16T05:15:33.3143250Z + scales 1.4.0 👷🏾♂️ ⬇ (328.67 kB)
2025-10-16T05:15:33.3144210Z + viridisLite 0.4.2 ⬇ (1.30 MB)
2025-10-16T05:15:33.4300630Z ℹ Getting 13 pkgs (15.04 MB)
2025-10-16T05:15:34.1472710Z ✔ Got RColorBrewer 1.1-3 (aarch64-apple-darwin20) (52.94 kB)
2025-10-16T05:15:34.5795680Z ✔ Got labeling 0.4.3 (aarch64-apple-darwin20) (61.31 kB)
2025-10-16T05:15:34.6110220Z ✔ Got lazyeval 0.2.2 (aarch64-apple-darwin20) (159.75 kB)
2025-10-16T05:15:34.6162950Z ✔ Got S7 0.1.1 (aarch64-apple-darwin20) (289.42 kB)
2025-10-16T05:15:34.6652890Z ✔ Got crosstalk 1.2.2.9000 (source) (416.15 kB)
2025-10-16T05:15:34.6943680Z ✔ Got gtable 0.3.6 (source) (148.15 kB)
2025-10-16T05:15:34.7022720Z ✔ Got scales 1.4.0 (source) (328.67 kB)
2025-10-16T05:15:34.7079270Z ✔ Got viridisLite 0.4.2 (aarch64-apple-darwin20) (1.30 MB)
2025-10-16T05:15:34.7136860Z ✔ Got isoband 0.2.7 (aarch64-apple-darwin20) (1.87 MB)
2025-10-16T05:15:34.7432650Z ✔ Got DT 0.34.0.9000 (source) (1.71 MB)
2025-10-16T05:15:34.7488470Z ✔ Got farver 2.1.2 (aarch64-apple-darwin20) (1.97 MB)
2025-10-16T05:15:34.7943300Z ✔ Got htmlwidgets 1.6.4.9000 (source) (2.92 MB)
2025-10-16T05:15:34.8013440Z ✔ Got ggplot2 4.0.0 (source) (3.81 MB)
2025-10-16T05:15:34.8186270Z ℹ Building gtable 0.3.6
2025-10-16T05:15:35.1397470Z ℹ Building htmlwidgets 1.6.4.9000
2025-10-16T05:15:35.2608380Z ✔ Installed lazyeval 0.2.2 (46ms)
2025-10-16T05:15:35.2655670Z ℹ Building crosstalk 1.2.2.9000
2025-10-16T05:15:37.0995320Z ✔ Built gtable 0.3.6 (1.9s)
2025-10-16T05:15:37.1141490Z ✔ Built htmlwidgets 1.6.4.9000 (2s)
2025-10-16T05:15:37.1649060Z ✔ Installed RColorBrewer 1.1-3 (17ms)
2025-10-16T05:15:37.2158370Z ✔ Installed S7 0.1.1 (31ms)
2025-10-16T05:15:37.2701590Z ✔ Installed farver 2.1.2 (30ms)
2025-10-16T05:15:37.3609440Z ✔ Installed isoband 0.2.7 (53ms)
2025-10-16T05:15:37.4197770Z ✔ Installed labeling 0.4.3 (29ms)
2025-10-16T05:15:37.5101790Z ✔ Installed viridisLite 0.4.2 (97ms)
2025-10-16T05:15:37.5193500Z ℹ Building scales 1.4.0
2025-10-16T05:15:37.5581420Z ✔ Built crosstalk 1.2.2.9000 (2.3s)
2025-10-16T05:15:37.5922510Z ✔ Installed gtable 0.3.6 (143ms)
2025-10-16T05:15:37.6803190Z ✔ Installed crosstalk 1.2.2.9000 (68ms)
2025-10-16T05:15:37.7565360Z ✔ Installed htmlwidgets 1.6.4.9000 (44ms)
2025-10-16T05:15:37.7669060Z ℹ Building DT 0.34.0.9000
2025-10-16T05:15:40.7920960Z ✔ Built DT 0.34.0.9000 (3s)
2025-10-16T05:15:40.9743840Z ✔ Installed DT 0.34.0.9000 (139ms)
2025-10-16T05:15:42.0769460Z ✔ Built scales 1.4.0 (4.5s)
2025-10-16T05:15:42.1612010Z ✔ Installed scales 1.4.0 (49ms)
2025-10-16T05:15:42.1714400Z ℹ Building ggplot2 4.0.0
2025-10-16T05:15:44.7569640Z ✖ Failed to build ggplot2 4.0.0 (2.5s)
2025-10-16T05:15:46.0497790Z Error : ! in callr subprocess.
2025-10-16T05:15:46.0599600Z Caused by error:
2025-10-16T05:15:46.0702350Z ! error in pak subprocess
2025-10-16T05:15:46.0805430Z Caused by error in `stop_task_build(state, worker)`:
2025-10-16T05:15:46.0905870Z ! Failed to build source package ggplot2.
2025-10-16T05:15:46.1006970Z Full installation output:
2025-10-16T05:15:46.1158060Z * installing *source* package ‘ggplot2’ ...
2025-10-16T05:15:46.1762700Z ** package ‘ggplot2’ successfully unpacked and MD5 sums checked
2025-10-16T05:15:46.1875950Z staged installation is only possible with locking
2025-10-16T05:15:46.1876520Z ** using non-staged installation
2025-10-16T05:15:46.1983780Z ** R
2025-10-16T05:15:46.2151380Z ** data
2025-10-16T05:15:46.2384970Z *** moving datasets to lazyload DB
2025-10-16T05:15:46.2546800Z ** inst
2025-10-16T05:15:46.2711360Z ** byte-compile and prepare package for lazy loading
2025-10-16T05:15:46.2872170Z Error : <element_geom> object properties are invalid:
2025-10-16T05:15:46.2981310Z - @ink
2025-10-16T05:15:46.3089570Z - @paper
2025-10-16T05:15:46.3195950Z - @accent
2025-10-16T05:15:46.3310180Z - @colour
2025-10-16T05:15:46.3420000Z - @fill
2025-10-16T05:15:46.3591230Z ##[error]Error: unable to load R code in package ‘ggplot2’
Ideally, r-lib/actions would install a binary that packagemanger has: https://packagemanager.posit.co/client/#/repos/cran/packages/overview?search=ggplot2&distribution=macos . But currently, r-lib/actions only installs PM binaries for windows/linux.
Thanks for the report! I don't have access to MacOS so I'd have to go trough the trouble of procuring that access to try and reproduce this. If anybody can reproduce this on their MacOS machine that'd be helpful to know.
2025-10-16T05:15:46.2872170Z Error : <element_geom> object properties are invalid: 2025-10-16T05:15:46.2981310Z - @ink 2025-10-16T05:15:46.3089570Z - @paper 2025-10-16T05:15:46.3195950Z - @accent 2025-10-16T05:15:46.3310180Z - @colour 2025-10-16T05:15:46.3420000Z - @fill
Usually the S7 errors on this topic are so friendly to let us know why the properties are invalid.
Hey all,
I'm actually having the same issue with the same error codes on Windows 10 and R 4.2.2.
Thanks for letting us know. I tried installing from CRAN or building from source in Windows 11 and R 4.2.3, but I'm not confronted with this problem.
Hello, I'm having the same issue trying to install ggplot2 (on macOS) with install.packages:
>` install.packages("ggplot2")
Installing package into ‘/Users/molliesweeney/Library/R/x86_64/4.2/library’
(as ‘lib’ is unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
ggplot2 3.4.4 4.0.0 FALSE
installing the source package ‘ggplot2’
trying URL 'https://cran.rstudio.com/src/contrib/ggplot2_4.0.0.tar.gz'
Content type 'application/x-gzip' length 3810397 bytes (3.6 MB)
==================================================
downloaded 3.6 MB
* installing *source* package ‘ggplot2’ ...
** package ‘ggplot2’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
Error : <element_geom> object properties are invalid:
- @ink
- @paper
- @accent
- @colour
- @fill
Error: unable to load R code in package ‘ggplot2’
Execution halted
ERROR: lazy loading failed for package ‘ggplot2’
* removing ‘/Users/molliesweeney/Library/R/x86_64/4.2/library/ggplot2’
The downloaded source packages are in
‘/private/var/folders/zx/4h0y_xx15l9b5fqm40nmzq600000gn/T/Rtmp80nB9Q/downloaded_packages’
Warning message:
In utils::install.packages("ggplot2") :
installation of package ‘ggplot2’ had non-zero exit status
@teunbrand Shiny's testing has only seen it on Mac w/ R 4.2.
Reprex on GHA: https://github.com/tidyverse/ggplot2/pull/6704
Running the GHA w/ debug enabled gives access to tmate.
I was able to get:
> pkgload::load_all()
ℹ Loading ggplot2
Error in `load_all()`:
! Failed to load R/theme-elements.R
Caused by error:
! <element_geom> object properties are invalid:
- @ink
- @paper
- @accent
- @colour
- @fill
Run `rlang::last_trace()` to see where the error occurred.
> rlang::last_trace()
<error/rlang_error>
Error in `load_all()`:
! Failed to load R/theme-elements.R
Caused by error:
! <element_geom> object properties are invalid:
- @ink
- @paper
- @accent
- @colour
- @fill
---
Backtrace:
▆
1. └─pkgload::load_all()
2. └─pkgload::load_code(path, quiet = quiet)
3. ├─withr (local) withr_with_dir(path, source_many(paths, encoding, env))
4. │ └─base::force(code)
5. └─pkgload:::source_many(paths, encoding, env)
6. ├─rlang::try_fetch(...)
7. │ ├─base::tryCatch(...)
8. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
9. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
10. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
11. │ └─base::withCallingHandlers(...)
12. └─pkgload:::source_one(file, encoding, envir = envir)
13. └─base::eval(exprs[i], envir)
14. └─base::eval(exprs[i], envir)
15. └─ggplot2:::element_geom(...) at ggplot2/R/theme-elements.R:356:1
16. └─S7::new_object(...) at ggplot2/R/theme-elements.R:344:5
17. └─S7::validate(object, recursive = !parent_validated)
18. └─base::stop(msg, call. = FALSE)
This points to https://github.com/tidyverse/ggplot2/blob/6e8ac77790c90ef6f8cedf91f932bb77c7a4b19e/R/theme-elements.R#L356-L363
After switching to constructing the value via
.default_geom_element <- NULL
on_load({
.default_geom_element <- element_geom(
ink = "black", paper = "white", accent = "#3366FF",
linewidth = 0.5, borderwidth = 0.5,
linetype = 1L, bordertype = 1L,
family = "", fontsize = 11,
pointsize = 1.5, pointshape = 19,
fill = NULL, colour = NULL
)
})
... I get the error
> rlang::last_trace()
<error/rlang_error>
Error in `load_all()`:
! Failed to load R/theme-elements.R
Caused by error in `get()`:
! object 'element_grob' not found
---
Backtrace:
▆
1. └─pkgload::load_all()
2. └─pkgload::load_code(path, quiet = quiet)
3. ├─withr (local) withr_with_dir(path, source_many(paths, encoding, env))
4. │ └─base::force(code)
5. └─pkgload:::source_many(paths, encoding, env)
6. ├─rlang::try_fetch(...)
7. │ ├─base::tryCatch(...)
8. │ │ └─base (local) tryCatchList(expr, classes, parentenv, handlers)
9. │ │ └─base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
10. │ │ └─base (local) doTryCatch(return(expr), name, parentenv, handler)
11. │ └─base::withCallingHandlers(...)
12. └─pkgload:::source_one(file, encoding, envir = envir)
13. └─base::eval(exprs[i], envir)
14. └─base::eval(exprs[i], envir)
15. └─S7::`method<-`(`*tmp*`, element_blank, value = `<fn>`) at ggplot2/R/theme-elements.R:484:1
16. └─S7:::register_method(generic, signature, value, env = parent.frame())
17. └─S7:::register_S3_method(generic, signature, method)
18. └─base::registerS3method(generic$name, class, method, envir = parent.frame())
19. └─base::get(genname, envir = envir)
Run rlang::last_trace(drop = FALSE) to see 5 hidden frames.
This feels like a weird S7 thing instead. I also don't know why a S7 method is being added to a regular function: element_grob(). 😞
Thanks for digging around Barret! I think it is eliminated that .default_geom_element is the only problem.
This feels like a weird S7 thing instead.
Yeah seems like that's right. I also don't understand why in the tests you've linked this doesn't happen for earlier R versions or why that version is fine on other platforms.
I also don't know why a S7 method is being added to a regular function: element_grob().
element_grob() is an S3 generic, and we're writing S7 methods for it. This preserves backward compatibility for extensions that have defined S3 methods for their classes. At some point S7 may fall back to S3 dispatch and we can make element_grob() and S7 generic, but that isn't the case yet.
We're unable to reproduce this using MacOS with R4.2 as well. We'd love more info is anyone is able to dig further.
Hi all, I was able to successfully install after updating my base R to 4.5.1