-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
935fea4
commit 63c28a8
Showing
2 changed files
with
58 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# R environments | ||
|
||
## How to set-up renv for reproducible research | ||
|
||
Create `DESCRIPTION` file e.g. | ||
|
||
``` | ||
Title: quarto_huang_2019 | ||
Depends: | ||
R (>= 3.7) | ||
Imports: | ||
knitr (==1.47), | ||
rmarkdown (==2.27), | ||
remotes (==2.5.0), | ||
tiff (==0.1-12) | ||
``` | ||
|
||
Then start new empty environment with `renv::init(bare=TRUE)`. | ||
|
||
When initialising, you should be prompted to only install from the `DESCRIPTION` - select yes to this. Otherwise, run the command yourself: `renv::settings$snapshot.type("explicit")`. | ||
|
||
You can then install the packages from DESCRIPTION by running `renv::install()`, and then create the lock file by running `renv::snapshot`. | ||
|
||
If you make any changes to the packages and versions, simply modified the `DESCRIPTION` file and then run `renv::install()` followed by `renv::snapshot`. | ||
|
||
If you run into issues where it cannot find a specific package/version, this may be due to the formatting of the version number. For example, for the package `tiff`: | ||
|
||
* `tiff` - installs latest version (0.1.12) | ||
* `tiff (==0.1.11)` - cannot find package | ||
* `tiff (==0.1-11)` - installs older version (0.1.11) | ||
|
||
The error was due to how those versions are formatted on CRAN, as you can see on the [tiff archive](https://cran.r-project.org/src/contrib/Archive/tiff/). | ||
|
||
## Basic renv commands | ||
|
||
To start new project environment, creating .RProfile: `renv::init()` | ||
To save state of project library to lockfile renv.lock: `renv::snapshot()` | ||
To return to environment in lockfile: `renv::restore()` | ||
|
||
## Binder | ||
|
||
Created using instructions from [here](https://ajstewartlang.github.io/23_introduction_to_binder/slides/23_introduction_to_binder.pdf) and [here](https://github.com/binder-examples/r). | ||
|
||
1. Create runtime.txt file with R version | ||
2. Create install.R file with package installations | ||
3. Navigate to https://mybinder.org/, paste in GitHub repository, set to "URL to open (optional)" and type in "rstudio", then launch | ||
|
||
## Rough notes | ||
|
||
R - | ||
\begin{itemize} | ||
\item Renv | ||
\item Posit Public Package Manager - can use Snapshot (earliest is Oct 2017, and 5 most recent versions of R), for Linux can install binary packages (which is much quicker, as usually R installs from source rather than binary unlike for Windows and Mac which makes it really slow) - \href{https://packagemanager.posit.co/client/#/repos/cran/setup}{source 1}, \href{https://docs.posit.co/faq/p3m-faq/#frequently-asked-questions}{source 2} | ||
\item Groundhog - can go back to R 3.2 and April 2015 (and apparently can patch to go earlier) - \href{https://www.brodrigues.co/blog/2023-01-12-repro_r/}{source 1} | ||
\item miniCRAN - \href{https://learn.microsoft.com/en-us/sql/machine-learning/package-management/create-a-local-package-repository-using-minicran?view=sql-server-ver16}{source 1} | ||
\item Docker - requires license for non-academic (e.g. NHS) use - but Podman can drop in as replacement. To do development inside a container isn't natively supported by RStudio but can use RStudioServer via Rocker. By default, it runs in ephemeral mode - any code created or saved is lost when close - but you can use volume argument to mount local folders - \href{https://towardsdatascience.com/running-rstudio-inside-a-container-e9db5e809ff8}{source 1} | ||
\end{itemize} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters