Skip to content

Wrong parameters due to partial matching #6408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Yunuuuu opened this issue Apr 9, 2025 · 0 comments · May be fixed by #6428
Open

Wrong parameters due to partial matching #6408

Yunuuuu opened this issue Apr 9, 2025 · 0 comments · May be fixed by #6428

Comments

@Yunuuuu
Copy link
Contributor

Yunuuuu commented Apr 9, 2025

Currently, the layer() function does not initialize all parameters for the associated Geom or Stat. This can lead to issues when multiple parameters share a common prefix. A typical example is StatSummary, which includes parameters like fun, fun.data, fun.max, and fun.min. If a Stat is invoked within a geom_* function using the stat argument, problems can arise in StatSummary$setup_params where params$fun may be incorrectly matched to fun.data, fun.max, or fun.min due to R's partial matching behavior.

Please see the warning message.

options(warnPartialMatchDollar = TRUE)
df <- data.frame(
  x = c(1, 1, 2, 2, 1, 1, 2, 2),
  y = c(1, 2, 2, 3, 2, 3, 1, 2),
  fill = c(rep("A", 4), rep("B", 4))
)
library(ggplot2)
# I won't draw anything, please see the warning message
p <- ggplot(df, aes(x, y, color = fill, fill = fill)) +
  geom_smooth(stat = "summary", fun.data = mean_se)
pdf()
print(p)
#> Warning in params$fun: partial match of 'fun' to 'fun.data'
dev.off()
#> png 
#>   2

Created on 2025-04-09 with reprex v2.1.0

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.2 (2024-10-31)
#>  os       Ubuntu 24.04.1 LTS
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language en
#>  collate  C.UTF-8
#>  ctype    C.UTF-8
#>  tz       Asia/Shanghai
#>  date     2025-04-09
#>  pandoc   3.1.3 @ /usr/bin/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.3      2024-06-21 [1] CRAN (R 4.4.0)
#>  colorspace    2.1-1      2024-07-26 [1] CRAN (R 4.4.2)
#>  digest        0.6.37     2024-08-19 [1] CRAN (R 4.4.2)
#>  dplyr         1.1.4      2023-11-17 [1] CRAN (R 4.4.0)
#>  evaluate      1.0.1      2024-10-10 [1] CRAN (R 4.4.2)
#>  fansi         1.0.6      2023-12-08 [1] CRAN (R 4.4.0)
#>  farver        2.1.2      2024-05-13 [1] CRAN (R 4.4.0)
#>  fastmap       1.2.0      2024-05-15 [1] CRAN (R 4.4.0)
#>  fs            1.6.5      2024-10-30 [1] CRAN (R 4.4.2)
#>  generics      0.1.3      2022-07-05 [1] CRAN (R 4.4.0)
#>  ggplot2     * 3.5.1.9000 2025-04-09 [1] Github (tidyverse/ggplot2@8b2a764)
#>  glue          1.8.0      2024-09-30 [1] CRAN (R 4.4.2)
#>  gtable        0.3.6      2024-10-25 [1] CRAN (R 4.4.2)
#>  htmltools     0.5.8.1    2024-04-04 [1] CRAN (R 4.4.0)
#>  knitr         1.49       2024-11-08 [1] CRAN (R 4.4.2)
#>  labeling      0.4.3      2023-08-29 [1] CRAN (R 4.4.0)
#>  lifecycle     1.0.4      2023-11-07 [1] CRAN (R 4.4.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.4.0)
#>  munsell       0.5.1      2024-04-01 [1] CRAN (R 4.4.0)
#>  pillar        1.9.0      2023-03-22 [1] CRAN (R 4.4.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.4.0)
#>  purrr         1.0.2      2023-08-10 [1] CRAN (R 4.4.0)
#>  R.cache       0.16.0     2022-07-21 [1] CRAN (R 4.4.0)
#>  R.methodsS3   1.8.2      2022-06-13 [1] CRAN (R 4.4.0)
#>  R.oo          1.26.0     2024-01-24 [1] CRAN (R 4.4.0)
#>  R.utils       2.12.3     2023-11-18 [1] CRAN (R 4.4.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.4.0)
#>  reprex        2.1.0      2024-01-11 [1] CRAN (R 4.4.0)
#>  rlang         1.1.4      2024-06-04 [1] CRAN (R 4.4.0)
#>  rmarkdown     2.29       2024-11-04 [1] CRAN (R 4.4.2)
#>  scales        1.3.0      2023-11-28 [1] CRAN (R 4.4.2)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.4.0)
#>  styler        1.10.3     2024-04-07 [1] CRAN (R 4.4.0)
#>  tibble        3.2.1      2023-03-20 [1] CRAN (R 4.4.0)
#>  tidyselect    1.2.1      2024-03-11 [1] CRAN (R 4.4.0)
#>  utf8          1.2.4      2023-10-22 [1] CRAN (R 4.4.0)
#>  vctrs         0.6.5      2023-12-01 [1] CRAN (R 4.4.0)
#>  withr         3.0.2      2024-10-28 [1] CRAN (R 4.4.2)
#>  xfun          0.49       2024-10-31 [1] CRAN (R 4.4.2)
#>  yaml          2.3.10     2024-07-26 [1] CRAN (R 4.4.2)
#> 
#>  [1] /home/yun/Rlibrary/4.4
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/lib/R/site-library
#>  [4] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment