Error creating notebook after running mapview()

I am hoping someone can shed light on this error I've started encountering when trying to save R notebooks after using mapview(). I have not been able to find other reports of this problem via Google searching; I apologize if I've missed something obvious.

Rstudio returns an error when saving the *.Rmd file if the file includes (or ever included) mapview output. The *.Rmd file saves as expected, but RStudio is unable to save the *.nb.html file.

The error shows up in a yellow bar at the top of the source window and says the following:

Error creating notebook: 'mode' for the clipboard must be 'r' or 'w'".

(I have included a screenshot of the error at the end for context).

Here is the entirety of a minimal reproducible example .Rmd file that gives me this error:

> ---
> title: "R Notebook"
> output: html_notebook
> ---
> 
> ```{r}
> library(mapview)
>
> # Dummy data
> x <- c(-112, -111, -110)
> y <- c(40, 41, 42)
>
> mapview(x,y)
> ````

Additional Information

  • The mapview map is rendered correctly inline in RStudio (see image below).
  • I am able to generate an html document with the mapview map if I change the output to "html_document" instead of html_notebook and then knit to html. However, I really prefer using the notebook format and have been able to include mapview maps in notebooks in the past.
  • After receiving the error, the working directory changed (e.g. typing getwd() in the console) to a directory within .Rproj.user instead of being the project directory itself. In this case it was changed to "../.Rproj.user/shared/notebooks/E09E316C-example01/1/s/lib".
  • The error persists even if I delete the mapview command, clear the chunk output, and try re-saving. Deleting the .Rproj.user directory so that it regenerates allows me to save the now mapview-free notebook.
  • I have no problems saving R notebooks for any .Rmd files that do not include a mapview command.

Here are my session details:

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  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] mapview_2.7.8

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.4.6       RColorBrewer_1.1-2 compiler_4.0.0     base64enc_0.1-3    class_7.3-17      
 [6] tools_4.0.0        uuid_0.1-4         digest_0.6.25      jsonlite_1.6.1     satellite_1.0.2   
[11] evaluate_0.14      lifecycle_0.2.0    lattice_0.20-41    viridisLite_0.3.0  png_0.1-7         
[16] rlang_0.4.6        DBI_1.1.0          crosstalk_1.1.0.1  yaml_2.2.1         xfun_0.14         
[21] e1071_1.7-3        stringr_1.4.0      raster_3.1-5       knitr_1.28         systemfonts_0.2.2 
[26] gdtools_0.2.2      htmlwidgets_1.5.1  stats4_4.0.0       classInt_0.4-3     leaflet_2.0.3     
[31] grid_4.0.0         webshot_0.5.2      svglite_1.2.3      sf_0.9-3           R6_2.4.1          
[36] rmarkdown_2.2      leafpop_0.0.5      sp_1.4-2           magrittr_1.5       scales_1.1.1      
[41] codetools_0.2-16   htmltools_0.4.0    units_0.6-6        mime_0.9           colorspace_1.4-1  
[46] brew_1.0-6         KernSmooth_2.23-17 stringi_1.4.6      munsell_0.5.0      leafem_0.1.1      
[51] markdown_1.1      

I am using the most recent version of Rstudio Desktop IDE (1.3)

Thank you for any guidance you might be able to provide on either the problem or additional troubleshooting that might be helpful!

Hi, it appears to me that the problem you describe is related to the version of R you use. When I copy-paste the code of your .Rmd file directly into the console, it works with R 3.6.3 but not with R 4.0.0

Thank you so much for testing this on your system! I really appreciate knowing that someone was able to replicate the issue. I don't have 3.6.3 installed, but do have 3.6.2. I tried running with that R version (after deleting the .Rproj.user directory) and unfortunately still end up with the same error. Some of my package versions are earlier under my 3.6.3 installation (rmarkdown 1.13 vs. 2.2; mapview 2.7.0 vs 2.7.8; markdown_1.0 vs 1.1) while some are the same (htmltools_0.4.0, htmlwidgets 1.5.1)

Any chance you'd be able to share your sessionInfo() so I can compare your package versions under your R 3.6.3 session?

Thanks again!

R version 3.6.2 (2019-12-12)
Platform: i386-w64-mingw32/i386 (32-bit)
Running under: Windows 10 x64 (build 18362)

Matrix products: default

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

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

other attached packages:
[1] mapview_2.7.0

loaded via a namespace (and not attached):
 [1] DBI_1.0.0          class_7.3-15       promises_1.0.1     lattice_0.20-38    compiler_3.6.2     htmlwidgets_1.5.1  xtable_1.8-4       viridisLite_0.3.0 
 [9] png_0.1-7          Rcpp_1.0.3         shiny_1.3.2        tools_3.6.2        units_0.6-3        rmarkdown_1.13     R6_2.4.1           raster_2.9-5      
[17] knitr_1.23         crosstalk_1.0.0    scales_1.0.0       digest_0.6.19      evaluate_0.14      mime_0.7           leafem_0.1.1       KernSmooth_2.23-16
[25] htmltools_0.4.0    munsell_0.5.0      grid_3.6.2         colorspace_1.4-1   httpuv_1.5.1       sf_0.8-1           rlang_0.4.4        leafpop_0.0.1     
[33] magrittr_1.5       leaflet_2.0.3      yaml_2.2.1         classInt_0.4-2     stats4_3.6.2       satellite_1.0.1    xfun_0.8           sp_1.3-2          
[41] e1071_1.7-2        later_0.8.0        RColorBrewer_1.1-2 base64enc_0.1-3    codetools_0.2-16   webshot_0.5.1      jsonlite_1.6       markdown_1.0

This config works

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252

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

other attached packages:
[1] mapview_2.7.8

loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 svglite_1.2.3 lattice_0.20-38 png_0.1-7
[5] class_7.3-15 assertthat_0.2.1 rprojroot_1.3-2 digest_0.6.25
[9] packrat_0.5.0 mime_0.9 R6_2.4.1 backports_1.1.6
[13] leafpop_0.0.5 stats4_3.6.3 e1071_1.7-3 gdtools_0.2.2
[17] rlang_0.4.5 uuid_0.1-4 rstudioapi_0.11 raster_3.1-5
[21] config_0.3 desc_1.2.0 webshot_0.5.2 stringr_1.4.0
[25] htmlwidgets_1.5.1 munsell_0.5.0 shiny_1.4.0.2 compiler_3.6.3
[29] httpuv_1.5.2 xfun_0.13 systemfonts_0.2.0 base64enc_0.1-3
[33] htmltools_0.4.0 roxygen2_7.1.0 codetools_0.2-16 attempt_0.3.0
[37] viridisLite_0.3.0 fansi_0.4.1 crayon_1.3.4 withr_2.2.0
[41] later_1.0.0 sf_0.9-2 grid_3.6.3 jsonlite_1.6.1
[45] satellite_1.0.2 xtable_1.8-4 lifecycle_0.2.0 DBI_1.1.0
[49] magrittr_1.5 dockerfiler_0.1.3 units_0.6-6 scales_1.1.0
[53] KernSmooth_2.23-16 cli_2.0.2 stringi_1.4.6 fs_1.4.1
[57] promises_1.1.0 remotes_2.1.1 leaflet_2.0.3 sp_1.4-1
[61] testthat_2.3.2 xml2_1.3.1 brew_1.0-6 RColorBrewer_1.1-2
[65] tools_3.6.3 leafem_0.1.1 golem_0.2.1 glue_1.4.0
[69] markdown_1.1 purrr_0.3.4 crosstalk_1.1.0.1 pkgload_1.0.2
[73] fastmap_1.0.1 yaml_2.2.1 colorspace_1.4-1 classInt_0.4-3

This config does not work

sessionInfo()
R version 4.0.0 (2020-04-24)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252 LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C LC_TIME=French_France.1252

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

other attached packages:
[1] mapview_2.7.8

loaded via a namespace (and not attached):
[1] Rcpp_1.0.4.6 svglite_1.2.3 lattice_0.20-41 png_0.1-7
[5] class_7.3-16 assertthat_0.2.1 rprojroot_1.3-2 digest_0.6.25
[9] mime_0.9 R6_2.4.1 backports_1.1.7 leafpop_0.0.5
[13] stats4_4.0.0 e1071_1.7-3 gdtools_0.2.2 rlang_0.4.6
[17] uuid_0.1-4 rstudioapi_0.11 raster_3.1-5 config_0.3
[21] desc_1.2.0 webshot_0.5.2 stringr_1.4.0 htmlwidgets_1.5.1
[25] munsell_0.5.0 shiny_1.4.0.2 compiler_4.0.0 httpuv_1.5.4
[29] xfun_0.14 systemfonts_0.2.2 base64enc_0.1-3 htmltools_0.4.0
[33] roxygen2_7.1.0 codetools_0.2-16 attempt_0.3.1 viridisLite_0.3.0
[37] fansi_0.4.1 crayon_1.3.4 withr_2.2.0 later_1.1.0.1
[41] sf_0.9-3 grid_4.0.0 jsonlite_1.6.1 satellite_1.0.2
[45] xtable_1.8-4 lifecycle_0.2.0 DBI_1.1.0 magrittr_1.5
[49] dockerfiler_0.1.3 units_0.6-6 scales_1.1.1 KernSmooth_2.23-16
[53] cli_2.0.2 stringi_1.4.6 fs_1.4.1 promises_1.1.0
[57] remotes_2.1.1 leaflet_2.0.3 sp_1.4-2 testthat_2.3.2
[61] xml2_1.3.2 brew_1.0-6 RColorBrewer_1.1-2 tools_4.0.0
[65] leafem_0.1.1 golem_0.2.1 glue_1.4.1 markdown_1.1
[69] purrr_0.3.4 crosstalk_1.1.0.1 pkgload_1.1.0 fastmap_1.0.1
[73] yaml_2.2.1 colorspace_1.4-1 classInt_0.4-3 knitr_1.28
[77] usethis_1.6.1

1 Like

@matt22 In case you have not yet found a solution, it seems that updating your version of RStudio could fix that:


At least for me it did with Version 1.3.1023.

Thanks for the suggestion and follow-up, @pirz. Unfortunately I just tried it again after installing the preview version of RStudio (version 1.3.1030) and the latest R release (version 4.0.1) and still receive the same error. In the meantime, I've gone back to just using leaflet() directly, though I do miss mapview's simplicity.

Unlike user "www"'s issue on the Stack Overflow post you mentioned, I have no problem seeing mapview output in RStudio's viewer or even in-line. The problem only happens when RStudio attempts (and fails) to save the notebook file (*.nb.html) associated with the notebook. Then I get the error message: Error creating notebook: 'mode' for the clipboard must be 'r' or 'w'.

Thanks again. I really appreciate the time you've taken to respond!

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