vignettes/ab-dev-in-docker-with-renv.Rmd
ab-dev-in-docker-with-renv.Rmd
You can use {devindocker} for any directory, project or even package. In the end, these are all folders on your computer.
tempdir <- tempdir()
my_project <- normalizePath(file.path(tempdir, "myproject"), mustWork = FALSE)
usethis::create_package(my_project, open = FALSE)
#> ✔ Creating '/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpAiiTlu/myproject/'
#> ✔ Setting active project to '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/RtmpAiiTlu/myproject'
#> ✔ Creating 'R/'
#> ✔ Writing 'DESCRIPTION'
#> Package: myproject
#> Title: What the Package Does (One Line, Title Case)
#> Version: 0.0.0.9000
#> Authors@R (parsed):
#> * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
#> license
#> Encoding: UTF-8
#> LazyData: true
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.0.0
#> ✔ Writing 'NAMESPACE'
#> ✔ Setting active project to '<no active project>'
Note that you need to launch your project with {devindocker} from outside this project. Never ever open it again locally (out of a Docker container) if you want to avoid problems with bad and not compatible local {renv} setup. It is recommended to create a project dedicated to launch {devindocker} projects.
Launch a Docker container with your directory inside. This should be a container with Rstudio server.
Common and project {renv} libraries will be stored on your local computer (See details in the next section).
You will need to set up {renv} the first time you launch the Docker container. Follow instructions in the "renv_instructions.Rmd"
file that is created inside your project.
# Which path to your working directory / project
path <- file.path(tempdir, "myproject")
# Which container (with Rstudio inside) ? ----
# https://hub.docker.com/r/rocker/verse
container <- "rocker/geospatial:4.0.1"
# Which port ? ----
# _Useful if multiple Rstudio Server to launch
port <- 8788
# My renv cache directory on my local computer
# Used as persistent drive for all you Docker container with {devindocker}
renv_cache <- "~/renv_cache"
# Start Docker project ----
devindocker::launch_proj_docker(
path = path,
container = container,
port = port,
renv_cache = renv_cache,
renv_inst = TRUE, # Add an Rmd with instructions inside your project
update_docker = TRUE
)
# Follow instructions in "renv_instructions.Rmd" to setup {renv}
When you’re done, do not forget to stop properly the Rstudio Server: Click on Top right button to quit or q()
in the console.
Then, stop the container.
# Stop Docker properly
stop_proj_docker(path = path)
{renv} has two levels of storing downloaded packages. First one is for the project, second one is for your computer:
".renv"
directory for the project is by default inside the project directory itself. This has some consequences when your project is a package during check()
because it is copied in the temporary directory of the check()
. A big project library may take some time and some place in your Docker container.
path
directory by default, which is the default {renv} behaviour. Indeed, if you use global cache (with renv_cache
), only symlinks are stored in these directory.renv_out = TRUE
to save these in a folder called ".renv"
, in the parent directory of your project renv_out_dir
. All project stored in the same parent directory will share this local ".renv"
library, using a specific folder inside. Inside the Docker container, the ".renv"
directory will be stored at the root of your RStudio server, in the Docker home directory. Show hidden files to se it.renv_cache
paramter.Hence,