mapview icon indicating copy to clipboard operation
mapview copied to clipboard

Cannot save R Notebook after calling mapview()

Open aquatic-ecology opened this issue 5 years ago • 5 comments

After calling mapview() from an R notebook in RStudio, the R notebook is unable to save, returning an error saying: Error creating notebook: 'mode' for the clipboard must be 'r' or 'w'.

I only get this error after calling mapview().

I have tested with R.4.0.0 and R3.6.2 and get the error with both. I have been able to use mapview() with R notebooks in the past and find it very helpful. Has anyone else had this issue or have ideas of how to troubleshoot? I appreciate any information anyone might be able to provide, even if it is that you cannot reproduce the problem, or that I should direct my questions elsewhere.

Thanks!

Minimal example .Rmd file:

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(mapview)    

# Dummy data
x <- c(-112, -111, -110) 
y <- c(40, 41, 42)
 
mapview(x, y) 

```

Session info:

R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices
[4] utils     datasets  methods  
[7] base     

other attached packages:
[1] mapview_2.7.8

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6      
 [2] RColorBrewer_1.1-2
 [3] compiler_4.0.0    
 [4] base64enc_0.1-3   
 [5] class_7.3-17      
 [6] tools_4.0.0       
 [7] uuid_0.1-4        
 [8] digest_0.6.25     
 [9] jsonlite_1.6.1    
[10] satellite_1.0.2   
[11] lifecycle_0.2.0   
[12] lattice_0.20-41   
[13] viridisLite_0.3.0 
[14] png_0.1-7         
[15] rlang_0.4.6       
[16] DBI_1.1.0         
[17] crosstalk_1.1.0.1 
[18] yaml_2.2.1        
[19] xfun_0.14         
[20] e1071_1.7-3       
[21] raster_3.1-5      
[22] systemfonts_0.2.3 
[23] gdtools_0.2.2     
[24] htmlwidgets_1.5.1 
[25] stats4_4.0.0      
[26] classInt_0.4-3    
[27] leaflet_2.0.3     
[28] grid_4.0.0        
[29] webshot_0.5.2     
[30] svglite_1.2.3     
[31] sf_0.9-3          
[32] R6_2.4.1          
[33] sp_1.4-2          
[34] leafpop_0.0.5     
[35] magrittr_1.5      
[36] scales_1.1.1      
[37] codetools_0.2-16  
[38] htmltools_0.4.0   
[39] units_0.6-6       
[40] mime_0.9          
[41] colorspace_1.4-1  
[42] brew_1.0-6        
[43] KernSmooth_2.23-17
[44] munsell_0.5.0     
[45] leafem_0.1.1      
[46] markdown_1.1      

aquatic-ecology avatar Jun 09 '20 21:06 aquatic-ecology

For now I can only say that I don't have the issue with R 3.6.1

master > devtools::session_info()
─ Session info ───────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.1 (2019-07-05)
 os       Pop!_OS 18.04 LTS           
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language en_GB:en                    
 collate  en_GB.UTF-8                 
 ctype    en_GB.UTF-8                 
 tz       Europe/Berlin               
 date     2020-06-10                  

─ Packages ───────────────────────────────────────────────────────────────────────────
 package      * version date       lib source                             
 assertthat     0.2.1   2019-03-21 [1] CRAN (R 3.6.1)                     
 backports      1.1.6   2020-04-05 [1] CRAN (R 3.6.1)                     
 base64enc      0.1-3   2015-07-28 [1] CRAN (R 3.6.1)                     
 brew           1.0-6   2011-04-13 [1] CRAN (R 3.6.1)                     
 callr          3.4.3   2020-03-28 [1] CRAN (R 3.6.1)                     
 class          7.3-14  2015-08-30 [4] CRAN (R 3.5.0)                     
 classInt       0.4-3   2020-04-07 [1] CRAN (R 3.6.1)                     
 cli            2.0.2   2020-02-28 [1] CRAN (R 3.6.1)                     
 clisymbols     1.2.0   2017-05-21 [1] CRAN (R 3.6.0)                     
 codetools      0.2-15  2016-10-05 [4] CRAN (R 3.5.0)                     
 colorspace     1.4-1   2019-03-18 [1] CRAN (R 3.6.0)                     
 crayon         1.3.4   2017-09-16 [1] CRAN (R 3.6.1)                     
 crosstalk      1.1.0.1 2020-03-13 [1] CRAN (R 3.6.1)                     
 DBI            1.1.0   2019-12-15 [1] CRAN (R 3.6.1)                     
 desc           1.2.0   2018-05-01 [1] CRAN (R 3.6.0)                     
 devtools       2.1.0   2019-07-06 [1] CRAN (R 3.6.0)                     
 digest         0.6.25  2020-02-23 [1] CRAN (R 3.6.1)                     
 e1071          1.7-3   2019-11-26 [1] CRAN (R 3.6.1)                     
 evaluate       0.14    2019-05-28 [2] CRAN (R 3.5.1)                     
 fansi          0.4.1   2020-01-08 [1] CRAN (R 3.6.1)                     
 fs             1.3.1   2019-05-06 [1] CRAN (R 3.6.0)                     
 gdtools        0.2.2   2020-04-03 [1] CRAN (R 3.6.1)                     
 glue           1.4.0   2020-04-03 [1] CRAN (R 3.6.1)                     
 htmltools      0.4.0   2019-10-04 [1] CRAN (R 3.6.0)                     
 htmlwidgets    1.5.1   2019-10-08 [1] CRAN (R 3.6.0)                     
 jsonlite       1.6.1   2020-02-02 [1] CRAN (R 3.6.1)                     
 KernSmooth     2.23-15 2015-06-29 [4] CRAN (R 3.5.0)                     
 knitr          1.28    2020-02-06 [1] CRAN (R 3.6.1)                     
 lattice        0.20-35 2017-03-25 [4] CRAN (R 3.5.0)                     
 leafem       * 0.1.1   2020-06-10 [1] local                              
 leaflet        2.0.3   2019-11-16 [1] CRAN (R 3.6.1)                     
 leafpop        0.0.5   2020-05-22 [1] local                              
 lifecycle      0.2.0   2020-03-06 [1] CRAN (R 3.6.1)                     
 magrittr       1.5     2014-11-22 [1] CRAN (R 3.6.1)                     
 mapview      * 2.8.1   2020-06-10 [1] local                              
 markdown       1.1     2019-08-07 [1] CRAN (R 3.6.0)                     
 memoise        1.1.0   2017-04-21 [1] CRAN (R 3.6.0)                     
 mime           0.9     2020-02-04 [1] CRAN (R 3.6.1)                     
 munsell        0.5.0   2018-06-12 [1] CRAN (R 3.6.0)                     
 packrat        0.5.0   2018-11-14 [1] CRAN (R 3.6.1)                     
 pkgbuild       1.0.6   2019-10-09 [1] CRAN (R 3.6.1)                     
 pkgload        1.0.2   2018-10-29 [1] CRAN (R 3.6.0)                     
 png            0.1-7   2013-12-03 [1] CRAN (R 3.6.0)                     
 prettyunits    1.1.1   2020-01-24 [1] CRAN (R 3.6.1)                     
 processx       3.4.2   2020-02-09 [1] CRAN (R 3.6.1)                     
 prompt         1.0.0   2020-01-18 [1] Github (gaborcsardi/prompt@b332c42)
 ps             1.3.2   2020-02-13 [1] CRAN (R 3.6.1)                     
 R6             2.4.1   2019-11-12 [1] CRAN (R 3.6.1)                     
 raster         3.0-12  2020-01-30 [1] CRAN (R 3.6.1)                     
 RColorBrewer   1.1-2   2014-12-07 [1] CRAN (R 3.6.0)                     
 Rcpp           1.0.4.6 2020-04-09 [1] CRAN (R 3.6.1)                     
 remotes        2.1.0   2019-06-24 [1] CRAN (R 3.6.0)                     
 rlang          0.4.5   2020-03-01 [1] CRAN (R 3.6.1)                     
 rmarkdown      1.13    2019-05-22 [1] CRAN (R 3.6.0)                     
 rprojroot      1.3-2   2018-01-03 [1] CRAN (R 3.6.0)                     
 rsconnect      0.8.16  2019-12-13 [1] CRAN (R 3.6.1)                     
 rstudioapi     0.11    2020-02-07 [1] CRAN (R 3.6.1)                     
 satellite      1.0.2   2019-12-09 [1] CRAN (R 3.6.1)                     
 scales         1.1.0   2019-11-18 [1] CRAN (R 3.6.1)                     
 sessioninfo    1.1.1   2018-11-05 [1] CRAN (R 3.6.0)                     
 sf             0.9-3   2020-05-08 [1] Github (r-spatial/sf@83180aa)      
 sp             1.4-1   2020-02-28 [1] CRAN (R 3.6.1)                     
 stringi        1.4.6   2020-02-17 [1] CRAN (R 3.6.1)                     
 stringr        1.4.0   2019-02-10 [1] CRAN (R 3.6.1)                     
 svglite        1.2.3   2020-02-07 [1] CRAN (R 3.6.1)                     
 systemfonts    0.1.1   2019-07-01 [1] CRAN (R 3.6.0)                     
 testthat       2.3.2   2020-03-02 [1] CRAN (R 3.6.1)                     
 units          0.6-6   2020-03-16 [1] CRAN (R 3.6.1)                     
 usethis        1.5.1   2019-07-04 [1] CRAN (R 3.6.0)                     
 uuid           0.1-4   2020-02-26 [1] CRAN (R 3.6.1)                     
 webshot        0.5.2   2019-11-22 [1] CRAN (R 3.6.1)                     
 withr          2.1.2   2018-03-15 [1] CRAN (R 3.6.0)                     
 xfun           0.12    2020-01-13 [1] CRAN (R 3.6.1)                     
 yaml           2.2.1   2020-02-01 [1] CRAN (R 3.6.1)                     

[1] /home/timpanse/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library

tim-salabim avatar Jun 10 '20 07:06 tim-salabim

Thank you for checking and for your reply. I have not been able to figure this out and have reverted to simply (or, rather, not-so-simply) using leaflet directly for my maps. I don't even know where such a problem would enter (like is it something in mapview, rmarkdown, rstudio). Since no one else seems to be reporting problems, there's also the possibility that there is something specific to my system causing the error. I can't be the only person who uses mapview in R Notebooks, right? For now, I'll keep my fingers crossed that the problem goes away in future updates to one of these packages, R, or RStudio itself. Thanks again!

aquatic-ecology avatar Jun 11 '20 21:06 aquatic-ecology

Brief update: I also get the error if I simply add leafem::addMouseCoordinates() to an existing leaflet map. Without the addMouseCoordinates() line, the leaflet map works just fine with RStudio and I can save the result as an html notebook. With the addMouseCoordinates() line, I receive the same error when RStudio tries to save the notebook: Error creating notebook: 'mode' for the clipboard must be 'r' or 'w'.

The code below produces the error:

---
title: "R Notebook"
output: html_notebook
---

```{r}
library(leaflet)

leaflet() %>% 
  addTiles() %>%
  addMarkers(lng=174.768, lat=-36.852, popup="The birthplace of R") %>%
  leafem::addMouseCoordinates()

```

aquatic-ecology avatar Jun 25 '20 21:06 aquatic-ecology

Could you please try:


---
title: "R Notebook"
output: 
  html_notebook:
    self_contained: false
---

```{r}
tst = clipr::write_clip("bla bla")
cat(clipr::read_clip())
```

Does this work or produce a similar error?

tim-salabim avatar Jun 27 '20 10:06 tim-salabim

That worked without any errors: the code ran and RStudio successfully saved the associated .nb.html file with the expected content.

Thanks!

aquatic-ecology avatar Jun 27 '20 17:06 aquatic-ecology