# `renv` WI
## R Libraries
1. Go to https://aceshiny-dev.bmrn.com/rlibrary/

2. Find a repo and R version match to want you want to use
> click on link in table,

> View the packages in the version you chose
3. Download renv.lock
> If this version looks correct, download the lock file by clicking on the `renv_lockfile` link


4. Copy the link to the repo

You will need this for step 6
## In RStudio
5. Select New Project and R version


6. copy the repo link **from the tabe**. Run `options(repos = <<your repo link>>)` in R console

Example,
```r=
options(
repos = "https://aceshiny-dev.bmrn.com/rspm/full-cran-as-of-2022-06-01/latest"
)
```
7. Run following command in R console
```r=
install.packages("renv")
library(renv)
```
8. Upload `renv.lock` to project folder level, make sure it’s called “`renv.lock`”

10. Run following command in R console
```r=
renv::activate()
Welcome to renv! It looks like this is your first time using renv.
This is a one-time message, briefly describing some of renv's functionality.
This package maintains a local cache of data on the filesystem at:
- '~/.local/share/renv'
This path can be customized -- see the documentation in `?paths`.
renv will also write to files within the active project folder, including:
- A folder 'renv' in the project directory, and
- A lockfile called 'renv.lock' in the project directory.
In particular, projects using renv will normally use a private, per-project
R library, in which new packages will be installed. This project library is
isolated from other R libraries on your system.
In addition, renv will attempt to update files within your project, including:
- .gitignore
- .Rbuildignore
- .Rprofile
Please read the introduction vignette with `vignette("renv")` for more information.
You can also browse the package documentation online at http://rstudio.github.io/renv.
By providing consent, you will allow renv to write and update these files.
Do you want to proceed? [y/N]:
```
Type `y` and hit enter/return. You should see the following:
```r=
* '~/.local/share/renv' has been created.
* Project '~/Projects/db-connections' loaded. [renv 0.9.3]
```
```r=
renv::restore()
The following package(s) will be updated:
# CRAN ===============================
- MASS [7.3-54 -> 7.3-51.6]
- Matrix [1.3-4 -> 1.2-18]
- boot [1.3-28 -> 1.3-25]
- codetools [0.2-18 -> 0.2-16]
- lattice [0.20-44 -> 0.20-41]
- mgcv [1.8-36 -> 1.8-31]
- nlme [3.1-152 -> 3.1-147]
- BH [* -> 1.72.0-3]
- DBI [* -> 1.1.0]
- DT [* -> 0.13]
- R6 [* -> 2.4.1]
- RColorBrewer [* -> 1.1-2]
...
...
...a long list of packages that will be udpated...
Do you want to proceed? [y/N]:
```
Type `y` and hit enter/return. RStudio will begin downloading/updating the packages.
10. removing packrat folder
-If you want to update to git, go to the Terminal pane in RStudio, run:
```bash=
git rm packrat/*
git push
```
The packrat folder will remove from git repository.
## Restart RStudio Before use!
11. Restart session by select "Session -> Restart R" (**Important, please do not skip!!**)

You should see this in your console:

12. run `renv::restore()` again
You will see another long list of packages to update
```r=
The following package(s) will be updated:
# CRAN ===============================
- MASS [7.3-54 -> 7.3-51.6]
- Matrix [1.3-4 -> 1.2-18]
- boot [1.3-28 -> 1.3-25]
...
...
...lots of packages
...
- xml2 [* -> 1.3.2]
- xtable [* -> 1.8-4]
- yaml [* -> 2.2.1]
- zip [* -> 2.0.4]
Do you want to proceed? [y/N]:
```
Type `y` and hit enter/return. RStudio will begin downloading/updating the packages.
13. (option) if you find any package is missing, install package as needed
14. Test your app
15. (option) if you have any new package installed, do the following steps:
A. `library(renv)`
B. `renv:snapshot()`
C. Send me your `renv.lock` file