knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(devindocker)

Create new package

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)

Use {renv} inside Docker and keep installation of packages

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} and its different storage directories

{renv} has two levels of storing downloaded packages. First one is for the project, second one is for your computer:

Hence,

Activate cache shared on host

Keep "renv_instructions.Rmd" up-to-date

# Which path to your working directory / project
path <- file.path(tempdir, "myproject")
update_renv_help(path = path, overwrite = TRUE)


ThinkR-open/devindocker documentation built on Jan. 28, 2021, 12:42 p.m.