Proper setting up of a reproducible quarto output based on a custom R package

Dear all,

I have a simple data pipeline where the data and the functional code are stored in a custom R package hosted on Azure DevOps and the final outputs are produced by quarto documents pointing to specific branches of the package.

I struggling to find a proper way to connect the quarto documents to this package in order to download it only if changed. Here's my code in the first chunck of the quarto doc:

```{r setup}
#| include: false
#| cache: false
#| message: false
#| warning: false

c("git2r", "renv", "remotes") |> 
  sapply(\(x) {
    if (!requireNamespace(x, quietly = TRUE)) {
      install.packages(x)
    }
  })

renv::activate()

gitcred <- git2r::cred_user_pass(
  username="username",
  password="repo-specific-pass")

remotes::install_git(
  "https://my-azure-repo.com/_git",
  build_manual = FALSE, build_vignettes = FALSE,
  upgrade = FALSE,
  dependencies = TRUE,
  ref = "2024-04-29_ECCMID", credentials = gitcred)

renv::snapshot()
```#

This code works, but it reinstalls the package every time. What should I change to avoid this?

This topic was automatically closed 90 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.

This is an environment configuration problem.

Depending on where this .qmd document is running, you should make your package available and then just call the library in your .qmd source.

If you want to install if not already, when quarto render is run, you need to make the installation conditional, or use renv::install() so that it manages and caches the package. You need to understand how renv is working to correctly do this.

Hope it helps