tests/testthat/test-reload.R

test_that("renv can be reloaded within the same session", {
  skip_on_cran()

  script <- renv_test_code({
    renv:::summon()

    # set up temporary library path
    libdir <- tempfile("renv-library-")
    ensure_directory(libdir)
    .libPaths(libdir)

    # install CRAN version of renv
    options(warn = 2L)
    options(repos = c(CRAN = "https://cloud.R-project.org"))
    install("renv@1.0.0")

    # unload and reload renv
    unloadNamespace("renv")
    loadNamespace("renv")

    # try writing out some data
    writeLines(paste(renv_package_version("renv"), renv_namespace_version("renv")))

  })

  output <- renv_system_exec(
    command = R(),
    args = c("--vanilla", "-s", "-f", renv_shell_path(script)),
    action = "reloading renv"
  )

  expect_equal(tail(output, n = 1L), "1.0.0 1.0.0")

})

Try the renv package in your browser

Any scripts or data that you put into this service are public.

renv documentation built on Sept. 19, 2023, 9:06 a.m.