Elektrine lite

← Feed

@infotroph@toot.cat

Post #2047460

2026-04-25 06:53 UTC

OK #RStats, can I conditionally use an imported function if it's available without check complaining in cases it isn’t? My use case: styling with `element_geom` if user has a new enough ggplot2, skipping it if not Conditioning on package version appears to _run_ correctly for all ggplot versions… ``` if (packageVersion(“ggplot2”) >= “4.0.0” ) { foo <- ggplot2::theme(…, geom = ggplot2::element_geom(…), …) } else { foo <- ggplot2::theme(…, …) }} ``` …but running `R CMD check` on a system with ggplot2 3.5 installed still warns “Missing or unexported object: ‘ggplot2::element_geom’”, presumably because the static analyzer doesn’t know the symbol is unreachable.

Replies (1)

  • @infotroph@toot.cat 2026-04-25 08:11

    #RStats Possibly solved with getExportedValue: ``` if (utils::packageVersion("ggplot2") >= "4.0.0") { elem_geom = getExportedValue(ns = "ggplot2", name = "element_geom") } else { elem_geom <- NULL } foo <- ggplot2::theme(…., geom = elem_geom, …) ``` This seems reasonable to me and passes check on the versions I've tried so far. Can't yet promise CRAN will approve…

    Open ##2073414