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:
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.
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 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!