knitr::opts_chunk$set( comment = "#", eval = F, options(repos="https://cran.rstudio.com" ) )
Is a light-weight tool for tracking R packages. It sits somewhere between reprex
and packrat
and revolves around CSV
files to store key package information.
The main goal of sesh
, is to make it simpler to reproduce R code. The ability to restore specific versions/commits of packages, is security for rapid development. And sesh
doesn't require anything beyond an Rscript, no Docker, external managers or RStudio projects.
devtools::install_github("nathancday/sesh")
library(sesh)
devtools::load_all("~/future/sesh/")
The concept behind sesh
is being able to record information about specific package versions for sharing with others, including your future self.
Using sesh
as part of your workflow gives you extra a little extra reprodu-security at the individual Rscript level.
It is very similar in aim to packrat
, but doesn't tie you into a RStudio Project. Instead of re-installing all of the required packages for each project, sesh
checks against currently installed versions and builds a disposable library path for itself in ~/.Trash/
if matching versions are required.
It does not touch R's deafult package search path.
We start by loading forcats
and tibble
from their current CRAN versions, just so we have some packages beyond R-core.
library(forcats) # v0.3.0 library(tidyr) # v0.8.1
session_info()
is an improvement on sessionInfo()
for readability, but is still fairly verbose.
sesh
aims to filter this output to only the attached packages. It also captures information about the current R-core
version.
sesh()
This dataframe is the essense of sesh
, a light, easy to share, record of your R session's essential information.
sesh
To save your current sesh()
, use save_sesh()
.
It will record the vital information to re-load all of your attached pacakge@verion
s and write it to disk as a CSV
.
save_sesh()
The default path
, is set up to name the output as "sesh_$SYS-DATE.csv". But it uses the glue
package to paste together R variables, so you could include custom gloabls to fit your tastes.
sesh
Just to show off the tools, let's re-check the CSV
we just saved for our current sesh
.
The function check_sesh()
will compare the currently loaded/installed package versions against a sesh
record. It will report which packages are already loaded, installed or require installation.
check_sesh("sesh_2018-08-19.csv") # check against currently installed versions
This just confirms our current session info matches the session info we saved two seconds ago, duh.
Let's pretend we are visiting a past script and let's pretend we wrote that past script sometime after forcats
intial realse, Aug 29, 2016.
To re-create this scenario, we will re-install two common cases:
devtools::install_version("forcats", "0.1.0", reload = F) devtools::install_github("tidyverse/tidyr@bd0c6b09052e91a4d283b2be6c8d3c5a6769b910", reload = F)
It is a good idea to restart your R session whenever you install an already attached package, like now.
library(forcats) library(tidyr) save_sesh("sesh_2017-10-01.csv")
Bringing us back to back to now.
install.packages("forcats") install.packages("tidyr") library(forcats) library(tidyr)
So now let's pretend we are picking up that year-old, dusty script.
read_sesh("sesh_2017-10-01.csv")
Sure, we are a little nervous because perhaps by upgrading our package versions we have inadvertantly broken something.
But our new found sesh
abilities make dealing with diffs simple and straight forward.
In order to see what pacakges are differnt between the "old script" and our library today, use check_sesh
.
check_sesh("sesh_2017-10-01.csv")
That's shows us the difference between our currently installed versions and the "past" versions.
The function install_sesh()
will re-install matching versions. By looking at source
and version
, it will attempts to install the sesh version in ~/.Trash/
and tell you if it was succesful. By keeping a temporary library in ~/.Trash/
, sesh
contains conflicts and doesn't take up disk space long term, because macOS
deletes any files in there after 30 days.
sesh
does not touch .libPaths()
, so it will not interfer with your globally installed package versions.
install_sesh("sesh_2017-10-01.csv")
Great, now we have the the right package versions installed to rerun our "old" script, but as it sits right now the matching versions are not loaded.
We need to call sesh_load()
to attach them. We should also restart the R session again because we re-installed loaded packages.
unloadNamespace("forcats") unloadNamespace("tidyr")
load_sesh("sesh_2017-10-01.csv")
And re-checking we see...
check_sesh("sesh_2017-10-01.csv")
All that is left to do now is source that old script!
When you are done working with the past sesh
versions, you can go back to your current global versions immediately. Just restart your R session and attach your libraries like normal.
There is also the helper function unload_sesh()
to do this without restarting, but it's vunerable to dependencies
,
unload_sesh("sesh_2017-10-01.csv") library(forcats) library(tidyr) sesh()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.