Skip to content

Commit b925bf5

Browse files
committed
feat(renvironments): clarify list dependencies section, explain minimum and specific version package installs, and other minor style tweaks (#85)
1 parent 17e5e19 commit b925bf5

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

short_courses/r_environments.ipynb

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,35 @@
299299
"\n",
300300
"#### 2. List dependencies\n",
301301
"\n",
302-
"Dependencies can be listed as `Imports` (required packages) or `Suggests` (optional/development packages).\n",
302+
"Dependencies can be listed as:\n",
303+
"\n",
304+
"* `Imports` (required packages).\n",
305+
"* Suggests` (optional/development packages).\n",
303306
"\n",
304307
"For non-package projects, it's simplest to list all dependencies under `Imports`, which will be identified by `renv` (whilst those under `Suggests` may not unless used in scripts).\n",
305308
"\n",
306309
"`Suggests` is more relevant when constructing a package, as it distinguishes packages necessary only for optional features, vignettes or testing, from those required within the package itself.\n",
307310
"\n",
308311
"**Note:** In the [R Packages](https://r-pkgs.org/description.html) book, they recommend that - in `DESCRIPTION` - no versions are specified, or a minimum version is specified if you know that an older version of specific package/s would break the code. This is why it is important to also create an `renv.lock` file (as below), so you do have a record of the exact versions used.\n",
309312
"\n",
313+
"Example `DESCRIPTION` with packages `dplyr` and `future`:\n",
314+
"\n",
315+
"```\n",
316+
"Package: example\n",
317+
"Title: Example DESCRIPTION\n",
318+
"Version: 0.0.0.9000\n",
319+
"Authors@R: \n",
320+
" person(\"Amy\", \"Heather\", , \"[email protected]\", role = c(\"aut\", \"cre\"))\n",
321+
"Description: This is an example DESCRIPTION, used for environment management.\n",
322+
"License: MIT + file LICENSE\n",
323+
"Encoding: UTF-8\n",
324+
"Roxygen: list(markdown = TRUE)\n",
325+
"RoxygenNote: 7.0.0\n",
326+
"Imports:\n",
327+
" dplyr\n",
328+
" future\n",
329+
"```\n",
330+
"\n",
310331
"#### 3. Install packages from `DESCRIPTION`\n",
311332
"\n",
312333
"Install packages listed in `DESCRIPTION` (and their dependencies) with:\n",
@@ -445,6 +466,19 @@
445466
"* Specify minimum or exact versions in your `DESCRIPTION` file.\n",
446467
"* Be aware that not all old versions are available for every R version; you may need to adjust your R version or accept a newer package.\n",
447468
"\n",
469+
"To specify a minimum version in `DESCRIPTION`:\n",
470+
"\n",
471+
"```\n",
472+
"Imports:\n",
473+
" dplyr (>= 1.0.0)\n",
474+
"```\n",
475+
"\n",
476+
"To install a particular version using `renv` (which is then captured in `renv.lock` by calling `renv::snapshot()`):\n",
477+
"\n",
478+
"```\n",
479+
"renv::install(\"[email protected]\")\n",
480+
"```\n",
481+
"\n",
448482
"#### Missing system dependencies\n",
449483
"\n",
450484
"Some R packages require external system libraries (e.g., C libraries, database clients) not installed by default.\n",
@@ -549,11 +583,11 @@
549583
"\n",
550584
"**Goal:** Clone a repository with a pre-configured `renv` environment, switch to the correct R version, restore dependencies, and run a basic R script.\n",
551585
"\n",
552-
"Example repository: [amyheather/renv-reproduce-activity](https://github.com/amyheather/renv-reproduce-activity/)\n",
586+
"**Repository:** [amyheather/renv-reproduce-activity](https://github.com/amyheather/renv-reproduce-activity/)\n",
553587
"\n",
554588
"```{dropdown} View solution\n",
555589
"\n",
556-
"1. **Clone the example repository.**\n",
590+
"1. **Clone the provided repository.**\n",
557591
" * `git clone https://github.com/amyheather/renv-reproduce-activity.git`\n",
558592
" * `cd renv-reproduce-activity`\n",
559593
"2. **Switch to the required R version.**\n",

0 commit comments

Comments
 (0)