You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I can also install packages in any of the usual ways, i.e., `install.packages()` or `pak::pkg_install("ggplot2")`, but you'll have to complete an additional step to update the `lock` file enumerating packages and dependencies. A call to `renv::snapshot()` should suffice.
255
+
We can also install packages in any of the usual ways, i.e., `install.packages()` or `pak::pkg_install("ggplot2")` and `renv` will intercept and install it in the environment.
256
+
Then we need to run the `snapshot()` function to update the `renv.lock` file with all the packages installed.
257
+
258
+
```r
259
+
renv::snapshot()
260
+
```
256
261
257
262
Now we can open the `renv.lock` file and see that it stores a lot of machine-readable information in plain text. However, you could also <kbd>COMMAND</kbd>+<kbd>F</kbd> (MacOS) or <kbd>CTRL</kbd>+<kbd>F</kbd> (Windows) to double check that the packages installed are now listed.
258
263
@@ -266,19 +271,26 @@ Let's delete the packages we just installed and then restore them using the exis
If you attempt to load these packages now, your get an error
270
276
271
277
```r
272
-
library("jsonlite)
278
+
library("jsonlite")
273
279
```
274
280
281
+
::::::::::::::: instructor
282
+
283
+
If the call to load `jsonlite` succeeds they might need to restart the R session because they loaded it previously and it is cached.
284
+
285
+
:::::::::::::::::::::::::::
286
+
275
287
```output
276
288
Error in library(jsonlite) : there is no package called ‘jsonlite’
277
289
```
278
290
279
291
To restore the packages from the `renv.lock`,
280
292
```r
281
-
renv::restore("renv.lock")
293
+
renv::restore()
282
294
```
283
295
284
296
If you attempt to load these packages now, it will work!
@@ -289,11 +301,11 @@ library("jsonlite)
289
301
290
302
### Ignoring files
291
303
292
-
Note that you only need to share the small `renv.lock` file with your collaborators - and not the entire `venv_spacewalks` directory with packages contained in your virtual environment.
293
-
We need to tell git to ignore that directory, so it is not tracked and shared - we do this by adding `venv_spacewalks` to the `.gitignore` in the root directory of our project.
304
+
Note that you only need to share the small `renv.lock` file with your collaborators - and not the entire `renv` directory with packages contained in your virtual environment.
305
+
We need to tell git to ignore that directory, so it is not tracked and shared - we do this by adding `renv` to the `.gitignore` in the root directory of our project.
If you are a MacOS user, remember the `.DS_Store` hidden file which is also not necessary to share with our project?
299
311
We can tell git to ignore it by adding it on a new line in `.gitignore` as pattern `**/.DS_Store` (so it will be ignored in any sub-folder of our project).
0 commit comments