Skip to content

Conversation

@teunbrand
Copy link
Collaborator

This PR aims to fix #4705 and replaces #4799.

Essentially it allows you to specifiy a scale/guide using the pkgname::-prefix.
By declaring the namespace we only need to search one namespace and we can avoid searching in all loaded namespaces.
Example guides:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

x <- validate_guide("legendry::colring")
is_guide(x)
#> [1] TRUE

x <- validate_guide("ggraph::edge_direction")
is_guide(x)
#> [1] TRUE

Example scale:

registerS3method(
  "scale_type", "pillar_num", 
  method = function(x) c("pillar::num")
)

is_attached("pillar")
#> [1] FALSE

# Note the class name ends with 'Num'
find_scale("x", pillar::num(1))
#> <ScaleContinuousPositionNum>
#>  Range:  
#>  Limits:    0 --    1

Created on 2025-11-17 with reprex v2.1.1

Practically, packages that implement this may want to declare both the unprefixed and prefixed versions while transitioning.
For example, the definition of the pillar method (here) may look like this:

scale_type.pillar_num <- function(x) c("num", "pillar::num", "continuous")`

@teunbrand teunbrand marked this pull request as draft November 17, 2025 12:45
@teunbrand

This comment was marked as resolved.

@teunbrand

This comment was marked as resolved.

@teunbrand
Copy link
Collaborator Author

Instead of adopting earlier advice on using external packages to test this, I'm now using a mocked asNamespace() for testing to return an environment of my choosing.

@teunbrand teunbrand marked this pull request as ready for review November 18, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support scale functions in packages not attached via scale_type()

1 participant