Bizarre geom_smooth error

p <- 
  ggplot2::ggplot(mtcars) + 
  ggplot2::aes(mpg, disp) + 
  ggplot2::geom_smooth(method = "gam", formula = y ~ s(x, bs="cs"))

list(p)

executing the above code interactively in RStudio produces the following warning and then prints the graph with no smooth:

[[1]]

Warning message:
Computation failed in `stat_smooth()`:
no applicable method for 'smooth.construct' applied to an object of class "cs.smooth.spec" 

This only happens when the plot is printed nested in a list. if I just try to print p directly, it plots just fine.

If I run the same code in Rgui it works fine. I can replicate this on some but not all of my accessible copies of R. In particular the one big difference is that I am getting this error on my Windows 10 machines, but not on a Windows 7 machine.

Here is my session info:

- Session info ---------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 4.0.5 (2021-03-31)
 os       Windows 10 x64              
 system   x86_64, mingw32             
 ui       RStudio                     
 language (EN)                        
 collate  English_United States.1252  
 ctype    English_United States.1252  
 tz       America/Chicago             
 date     2021-04-19                  

- Packages -------------------------------------------------------------------------------------------------
 package     * version date       lib source        
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)
 cachem        1.0.4   2021-02-13 [1] CRAN (R 4.0.5)
 callr         3.6.0   2021-03-28 [1] CRAN (R 4.0.5)
 cli           2.4.0   2021-04-05 [1] CRAN (R 4.0.5)
 colorspace    2.0-0   2020-11-11 [1] CRAN (R 4.0.5)
 crayon        1.4.1   2021-02-08 [1] CRAN (R 4.0.5)
 DBI           1.1.1   2021-01-15 [1] CRAN (R 4.0.5)
 desc          1.3.0   2021-03-05 [1] CRAN (R 4.0.5)
 devtools      2.4.0   2021-04-07 [1] CRAN (R 4.0.5)
 digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.5)
 dplyr         1.0.3   2021-01-15 [1] CRAN (R 4.0.3)
 ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)
 fansi         0.4.2   2021-01-15 [1] CRAN (R 4.0.5)
 fastmap       1.1.0   2021-01-25 [1] CRAN (R 4.0.5)
 fs            1.5.0   2020-07-31 [1] CRAN (R 4.0.2)
 generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.5)
 ggplot2       3.3.3   2020-12-30 [1] CRAN (R 4.0.5)
 glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.3)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.0.2)
 lattice       0.20-41 2020-04-02 [2] CRAN (R 4.0.5)
 lifecycle     1.0.0   2021-02-15 [1] CRAN (R 4.0.5)
 magrittr      2.0.1   2020-11-17 [1] CRAN (R 4.0.3)
 Matrix        1.2-18  2019-11-27 [1] CRAN (R 4.0.3)
 memoise       2.0.0   2021-01-26 [1] CRAN (R 4.0.5)
 mgcv          1.8-33  2020-08-27 [1] CRAN (R 4.0.5)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.0.2)
 nlme          3.1-149 2020-08-23 [1] CRAN (R 4.0.5)
 pillar        1.6.0   2021-04-13 [1] CRAN (R 4.0.5)
 pkgbuild      1.2.0   2020-12-15 [1] CRAN (R 4.0.5)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)
 pkgload       1.2.1   2021-04-06 [1] CRAN (R 4.0.5)
 prettyunits   1.1.1   2020-01-24 [1] CRAN (R 4.0.2)
 processx      3.5.1   2021-04-04 [1] CRAN (R 4.0.5)
 ps            1.6.0   2021-02-28 [1] CRAN (R 4.0.5)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)
 R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.5)
 remotes       2.3.0   2021-04-01 [1] CRAN (R 4.0.5)
 rlang         0.4.10  2020-12-30 [1] CRAN (R 4.0.3)
 rprojroot     2.0.2   2020-11-15 [1] CRAN (R 4.0.3)
 scales        1.1.1   2020-05-11 [1] CRAN (R 4.0.2)
 sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.2)
 testthat      3.0.2   2021-02-14 [1] CRAN (R 4.0.5)
 tibble        3.1.0   2021-02-25 [1] CRAN (R 4.0.5)
 tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)
 usethis       2.0.1   2021-02-10 [1] CRAN (R 4.0.5)
 utf8          1.2.1   2021-03-12 [1] CRAN (R 4.0.5)
 vctrs         0.3.7   2021-03-29 [1] CRAN (R 4.0.5)
 withr         2.4.2   2021-04-18 [1] CRAN (R 4.0.5)

[1] C:/Users/Tyler/Documents/R/win-library/4.0
[2] C:/Program Files/R/R-4.0.5/library

When I try to debug what is happening (using debug(print)), in Rstudio all the strings seem to print with different character encodings. For example, this is what I see in the debugged source window:


function (x, ...) 
UseMethod("ÿþprintÿþ")

It does appear likely to be a Windows issue.

suppressPackageStartupMessages({
  library(ggplot2)
})

p <- ggplot(mtcars,aes(mpg, disp))

p +
  geom_smooth(method = "gam", formula = y ~ s(x, bs="cs")) +
  theme_minimal() -> out

l <- list(out)

l[[1]]

sessionInfo()
#> R version 4.0.4 (2021-02-15)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Pop!_OS 20.10
#> 
#> Matrix products: default
#> BLAS:   /usr/local/lib/R/lib/libRblas.so
#> LAPACK: /usr/local/lib/R/lib/libRlapack.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] ggplot2_3.3.3
#> 
#> loaded via a namespace (and not attached):
#>  [1] pillar_1.6.0      compiler_4.0.4    highr_0.9         tools_4.0.4      
#>  [5] digest_0.6.27     lattice_0.20-41   nlme_3.1-152      evaluate_0.14    
#>  [9] lifecycle_1.0.0   tibble_3.1.1      gtable_0.3.0      mgcv_1.8-35      
#> [13] pkgconfig_2.0.3   rlang_0.4.10      Matrix_1.3-2      reprex_2.0.0     
#> [17] DBI_1.1.1         yaml_2.2.1        xfun_0.22         withr_2.4.2      
#> [21] styler_1.4.1      stringr_1.4.0     dplyr_1.0.5       knitr_1.32       
#> [25] generics_0.1.0    fs_1.5.0          vctrs_0.3.7       grid_4.0.4       
#> [29] tidyselect_1.1.0  glue_1.4.2        R6_2.5.0          fansi_0.4.2      
#> [33] rmarkdown_2.7     farver_2.1.0      purrr_0.3.4       magrittr_2.0.1   
#> [37] splines_4.0.4     backports_1.2.1   scales_1.1.1      ellipsis_0.3.1   
#> [41] htmltools_0.5.1.1 assertthat_0.2.1  colorspace_2.0-0  labeling_0.4.2   
#> [45] utf8_1.2.1        stringi_1.5.3     munsell_0.5.0     crayon_1.4.1

I don't have a Windows box that I can test this on.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.