Skip to content

scale_y_continuous() fails if inside a function called via double colon pkg::fun(...) #5436

Closed

Description

@averissimo

I found a problem with recent PR #5343 when scale_y_continuous was called inside a package function via double colon

I expected the function not to throw an error

Here is the code to reproduce the bug:

Please note that the problem is not with {tern} itself, as the call without double colon succeeds

install.package("tern")
remotes::install_github("tidyverse/ggplot2")

library(tern)

# example from tern::g_lineplot function
library(nestcolor)

adsl <- tern_ex_adsl
adlb <- tern_ex_adlb %>% dplyr::filter(ANL01FL == "Y", PARAMCD == "ALT", AVISIT != "SCREENING")
adlb$AVISIT <- droplevels(adlb$AVISIT)
adlb <- dplyr::mutate(adlb, AVISIT = forcats::fct_reorder(AVISIT, AVISITN, min))
g_lineplot(adlb, adsl, subtitle = "Laboratory Test:")

# This call falls on if clause `... && !startsWith(as.character(call[[1]]), "scale_")` as it has length = 3
tern::g_lineplot(adlb, adsl, subtitle = "Laboratory Test:")

Activity

  1. added
    bug
    on Sep 26, 2023
  2. teunbrand commented on Sep 26, 2023

    @teunbrand
    Collaborator

    Thanks for the report! I can reproduce this bug. A more minimal reprex:

    # Current main branch
    devtools::load_all("~/packages/ggplot2")
    #> ℹ Loading ggplot2
    
    env <- new.env()
    env$foo <- function() {
      ggplot() + 
        geom_point(aes(x = "A", y = 2)) +
        scale_x_continuous()
    }
    
    env$foo()
    #> Error in is.null(call) || !startsWith(as.character(call[[1]]), "scale_"): 'length = 3' in coercion to 'logical(1)'

    Created on 2023-09-26 with reprex v2.0.2

  3. added a commit that references this issue on Sep 27, 2023
    45d2a43
  4. added a commit that references this issue on Oct 2, 2023
    fa26a55
  5. added a commit that references this issue on Oct 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions