throw your computer into the ocean with confidence
warmup
starting R
installing R packages
creating reproducible environments
installing / upgrading R
R packages
base R
For example, have you used lattice recently? 🤷
library(lattice)
By default, in the default library
.Library
All libraries for the current session
.libPaths()
All installed packages
installed.packages()
usethis::use_course("rstats-wtf/wtf-explore-libraries")
# use_course("rstats-wtf/wtf-explore-libraries", destdir = "my/new/location")
07:30
warmup
starting R
installing R packages
creating reproducible environments
installing / upgrading R
Sometimes we want to change the way our code behaves without having to change the code.
startup files must end in a newline.
R may silently throw away the last line if you don’t do this.
.Renviron
environment variables
a […] named value that can affect the way running processes will behave on a computer
.Renviron
✅ R-specific environment variables
✅ API keys or other secrets
❌ R code
.Renviron
usethis::edit_r_environ(scope = ?)
~/.Renviron
path/to/your/project/.Renviron
.Renviron
PATH="${RTOOLS40_HOME}\usr\bin;${PATH}" # windows users
GITHUB_PAT=ghp_gVa6xK3bwERJ7xpWvoWj2dXMit4z43fWE8R
CONNECT_API_KEY=DaYK2hBUriSBYUEGIAiyXsRJHSjTYJN3
R_HISTSIZE=100000
Sys.getenv()
.Renviron
usethis::edit_r_environ()
WTF_USER=<your name>_user
CTRL + SHIFT + F10
CMD + SHIFT + 0
Sys.getenv("WTF_USER")
02:00
.Renviron
usethis::edit_r_environ("project")
WTF_PROJECT=<your name>_project
CTRL + SHIFT + F10
CMD + SHIFT + 0
Sys.getenv("WTF_PROJECT")
02:00
what’s the value of WTF_USER
after you set WTF_PROJECT
?
.Renviron
recapproject .Renviron
“short-circuits”
if it exists, your user .Renviron
will not be evaluated
.Rprofile
R code that runs at the start of each session
TRUE
🧑💻
☝️ most .Rprofile
customization
FALSE
🤖
R -e script.R
.Rprofile
.Rprofile
If it matters for code you share, it should not be in .Rprofile
.Rprofile
?options(stringsAsFactors = FALSE)
library(tidyverse)
f <- dplyr::filter
theme_set(theme_bw())
Why might these be safe to put in .Rprofile
?
02:00
https://github.com/search?q=.Rprofile
usethis::edit_r_profile()
print("from my user Rprofile")
CTRL + SHIFT + F10
CMD + SHIFT + 0
usethis::edit_r_profile("project")
print("from my project Rprofile")
CTRL + SHIFT + F10
CMD + SHIFT + 0
05:00
.Rprofile
recapproject .Rprofile
“short-circuits”
if it exists, your user .Rprofile
will not be evaluated
.Renviron
.Rprofile
warmup
starting R
installing R packages
creating reproducible environments
installing / upgrading R
CRAN | Posit Public Package Manager (p3m) | |
---|---|---|
windows | ✅ | ✅ |
mac OS | ✅ | ✅ |
linux | ❌ | ✅ |
> install.packages("parallelly", repos = "https://cran.rstudio.com")
Installing package into ‘C:/Users/WDAGUtilityAccount/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
parallelly 1.31.0 1.32.1 FALSE
installing the source package ‘parallelly’
trying URL 'https://cran.rstudio.com/src/contrib/parallelly_1.32.1.tar.gz'
Content type 'application/x-gzip' length 124853 bytes (121 KB)
downloaded 121 KB
* installing *source* package 'parallelly' ...
** package 'parallelly' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'parallelly'
finding HTML links ... done
as.cluster html
autoStopCluster html
availableConnections html
availableCores html
availableWorkers html
canPortBeUsed html
cpuLoad html
find_rshcmd html
freeCores html
freePort html
getOption2 html
isConnectionValid html
isForkedChild html
isForkedNode html
isLocalhostNode html
isNodeAlive html
makeClusterMPI html
makeClusterPSOCK html
parallelly.options html
pid_exists html
supportsMulticore html
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (parallelly)
> install.packages("parallelly", repos = "https://cran.rstudio.com")
Installing package into ‘C:/Users/edavi/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/parallelly_1.32.1.zip'
Content type 'application/zip' length 306137 bytes (298 KB)
downloaded 298 KB
package ‘parallelly’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\edavi\AppData\Local\Temp\Rtmpa2s3e8\downloaded_packages
> install.packages("renv", repos="https://cran.rstudio.com")
Installing package into ‘/Users/edavidaja/Library/R/x86_64/4.1/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.1/renv_0.15.5.tgz'
Content type 'application/x-gzip' length 1866760 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
The downloaded binary packages are in
/var/folders/b5/fl4ff68d23s148tg1_1gnflc0000gn/T//RtmpMk69B0/downloaded_packages
> install.packages("remotes")
Installing package into ‘C:/Users/WDAGUtilityAccount/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://packagemanager.rstudio.com/all/latest/bin/windows/contrib/4.2/remotes_2.4.2.zip'
Content type 'binary/octet-stream' length 399930 bytes (390 KB)
downloaded 390 KB
package ‘remotes’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpA1edRi\downloaded_packages
Does Posit Package Manager serve a binary of dplyr
for R 3.4?
02:00
Running `R CMD build`...
* checking for file 'C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpkTUH61\remotes192027624804\tidyverse-dplyr-36ef054/DESCRIPTION' ... OK
* preparing 'dplyr':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
-----------------------------------
* installing *source* package 'dplyr' ...
** using staged installation
** libs
Warning in system(cmd) : 'make' not found
ERROR: compilation failed for package 'dplyr'
* removing 'C:/Users/WDAGUT~1/AppData/Local/Temp/Rtmp6hYuyV/Rinst1334d1a23d1/dplyr'
-----------------------------------
ERROR: package installation failed
Warning in untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
* installing *source* package 'dplyr' ...
** using staged installation
** libs
c:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -O2 -Wall -mtune=core2 -c filter.cpp -o filter.o
sh: line 1: c:/Rtools/mingw_64/bin/g++: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: filter.o] Error 127
ERROR: compilation failed for package 'dplyr'
* removing 'C:/Users/edavi/DOCUME~1/projects/WTF-PR~1/renv/staging/1/dplyr'
Error: install of package 'dplyr' failed
devtools::has_devel()
## Your system is ready to build packages!
install a package from r-universe
open the personal-radmin
project
install.packages("gitcellar")
# not on cran!
update your project .Rprofile
:
usethis::edit_r_profile(scope = "project")
save .Rprofile
and restart R
install.packages("gitcellar")
05:00
gitcellar
from binary or source?
binaries are usually preferred, but for development versions of packages, you may need to install from source.
warmup
starting R
installing R packages
creating reproducible environments
installing / upgrading R
The quick and dirty approach you took then comes right back at you as a boomerang.
Therefore, ban the concept of one-off altogether. No matter what the asker says, it will have to be done again, always!
3/9— Edwin Thoen (@edwin_thoen) May 16, 2022
time travel!
open the personal-radmin
project
update your project .Rprofile
with a date-based snapshot of CRAN
Restart R
install.packages("dplyr")
what version of dplyr did you install?
05:00
.libPaths()
.libPaths()
create an isolated project library
wtf-fix-paths
projectinstall.packages("renv")
renv::init()
renv::status()
library(parallelly)
to any file in the wtf-fix-paths/R
directory; save filerenv::status()
install.packages("parallelly")
renv::status()
renv::snapshot()
(y
proceed)library(parallelly)
from the file you added it to; save filerenv::status()
10:00
renv::install()
or install.packages()
with shims enabled
renv::install("jsonlite")
renv::install("jsonlite@1.2") # at version
renv::install"jeroen/jsonlite") # latest
renv::install"jeroen/jsonlite@80854359976250f30a86a6992c0d8c3b3d95473d") # at SHA
renv::install("path/to/package") # local source
for reprexes, tweets, and other ephemera:
~/Documents/scratch
warmup
starting R
installing R packages
creating reproducible environments
installing / upgrading R
software whose job it is to install other software
🙉 not the same kinds of packages as PPM
package manager | |
---|---|
windows | scoop, chocolatey, winget |
macOS | homebrew |
linux | homebrew, apt, yum, zypper |
Avoid installing your language with a package manager
using your package manager, install a language manager
language managers for other languages:
pyenv nvm rustup
CTRL + CLICK
using your language manager, install a language version:
❯ rig install --help
rig-add
DESCRIPTION:
Download and install an R version, from the official sources.
It keeps the already installed R versions, except versions within the
same minor branch, see below.
EXAMPLES:
# Add the latest release
rig add release
# Install specific version
rig add 4.1.2
# Install latest version within a minor branch
rig add 4.1
using your desired version of the language, install an environment manager:
install.packages("renv")
using your environment manager, install your project’s dependencies:
create a new environment
restore an already defined environment
read the rig FAQ, or the rswitch guide
rig
10:00