Skip to content
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

Some mapview usage prevents caching chunk on knitr #473

Open
cderv opened this issue Mar 13, 2024 · 0 comments
Open

Some mapview usage prevents caching chunk on knitr #473

cderv opened this issue Mar 13, 2024 · 0 comments

Comments

@cderv
Copy link

cderv commented Mar 13, 2024

Initially, this comes from a report in Quarto: quarto-dev/quarto-cli#9058

Here is a reprex with mapview

---
title: Test Document
output: html_document
---

```{r}
library(mapview)
library(plainview)
```

```{r, cache = TRUE}
mapview(poppendorf[[5]], legend = TRUE, layer.name = "T3")
```

You can run this once (using knit button to run in a background R session), which will cache the chunk. But on subsequent runs, you'll get an error.

Error:
! path for html_dependency not found: C:/Users/chris/AppData/Local/Temp/RtmpyErHiA/data_stars779843bf736_754d19
Backtrace:
    ▆
 1. └─rmarkdown::render("C:/Users/chris/Documents/test.Rmd", encoding = "UTF-8")
 2.   └─output_format$pre_processor(...)
 3.     └─rmarkdown (local) base(...)
 4.       └─rmarkdown:::html_extras_for_document(...)
 5.         └─rmarkdown (local) dependency_resolver(all_dependencies)
 6.           └─base::lapply(dependencies, validate_html_dependency)
 7.             └─rmarkdown (local) FUN(X[[i]], ...)
 8.               └─rmarkdown:::stop2("path for html_dependency not found: ", file)

What happens is that it will try to load what is cached, and as it is using another R session temp directory for one of its dependency.

This comes from

mapview/R/raster.R

Lines 124 to 127 in f35e32f

if (label)
m = leafem::addImageQuery(m, x, group = grp, layerId = grp,
type = query.type, digits = query.digits,
position = query.position, prefix = query.prefix)

and so from leafem :
https://github.com/r-spatial/leafem/blob/6d6831352038b8f7462ff7afa698050c4e46fb5e/R/imagequery.R#L77

https://github.com/r-spatial/leafem/blob/6d6831352038b8f7462ff7afa698050c4e46fb5e/R/utils.R#L65-L80

as makepathStars is created the file in a temporary directory.

I opened here because it was easier for me to build a mapview example, and I don't know if there could be other HTML dependencies in mapview with the same problem

FWIW, This is related to another issue we had with leaflet and leaflet.providers that did not support caching with knitr due to same usage of HTML dependency being in temporary directory

Hope this helps understand the issue. Happy to clarify or discuss any feedback you may have on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant