• Stars
    star
    140
  • Rank 252,278 (Top 6 %)
  • Language
    R
  • License
    Other
  • Created over 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An inversion of renv for low effort reproducible R package libraries

capsule

capsule status badge

Installation

R Universe

install.packages(
   "capsule", 
   repos = c(mm = "https://milesmcbain.r-universe.dev", getOption("repos")))

Overview

A capsule is a stable project-specific R package library that you consciously choose to execute code within. Think of it as representing 'production', while your normal interactive R session represents 'development'.

You develop interactively in a dynamic package environment. You run code for real in a well-defined static capsule. Periodically you'll want to have your development environment reflected in the capsule as new stuff is integrated.

When sharing with others, a capsule is the fallback that ensures your code can always be run, no matter what issues appear in your collaborator's development environment.

Usage

There are 3 functions you need to know about to use capsule: capsule::create(), capsule::run(), capsule::recreate().

create() a capsule for my pipeline

> capsule::create("./packages.R")
Finding R package dependencies ... Done!
* Discovering package dependencies ... Done!
* Copying packages into the cache ... [132/132] Done!
The following package(s) will be updated in the lockfile:

# CRAN ===============================
- anytime          [* -> 0.3.6]
- askpass          [* -> 1.1]
...TRUNCATED...
- BH               [* -> 1.69.0-1]
- spatial          [* -> 7.3-11]
- survival         [* -> 2.44-1.1]

# GitHub =============================
- geojsonsf        [* -> SymbolixAU/geojsonsf]
- h3jsr            [* -> obrl-soil/h3jsr]
- jsonify          [* -> SymbolixAU/jsonify]
- qfes             [* -> milesmcbain/qfes]
- renv             [* -> rstudio/renv]

* Lockfile written to 'c:/repos/capsule/renv.lock'.

You supply a vector of file paths to extract dependencies from. The default is "./packages.R". These dependencies are copied from your regular (dev) library to your local capsule.

Notice how this is easier when you keep your library calls all in one place? 😉

You'll notice some things created in your project folder. Assuming you have the project under version control... you definitely want to commit the ./renv.lock file. This will allow someone else to run() code in the capsule context.

run() code in the capsule

Render a document in the capsule:

capsule::run(rmarkdown::render("doc/analysis.Rmd"))

Or run your {targets} plan in the capsule:

capsule::run(targets::tar_make())

So what about code that you've just been handed? It has a renv.lock but no local library? How do you build the library to run the code? You don't! run() will check to see if a local library exists, and build it if required. (You can do this manually with reproduce_lib(), if that feels better before calling run()).

recreate() the capsule

You've done some development work, updated a few dependencies, and the output has tested successfully. You can make the capsule reflect the project dependencies installed in your dev environment using recreate().

Other Useful Stuff

Debugging in the capsule with a REPL

Try capsule::repl() to attach a REPL for a new R process in the context of the capsule. This is handy for interactive work like debugging. The tradeoff here is that depending what editor you use strange behaviour may be induced by the outer REPL being overtaken. In ESS I lose my autocompletions.

Automating lockfile creation with capshot()

capshot() is designed to create a lockfile for your project very quickly so that it can be integrated into your build or rendering pipeline. On my {tflow} projects laden with dependencies it typically takes 1-2 seconds to detect the dependencies and write the lockfile.

Unlike create() it does not populate a local library automatically. See:

  • capsule::capshot() - fast lockfile creation
  • capsule::capshot_str() - quickly generate the lockfile json for further processing, e.g. embedding in a document.

Helpers

  • capsule::delete() - remove the capsule (local library and lockfile).
  • capsule::delete_local_lib() - remove the local library.
  • capsule::delete_lockfile() - remove the lockfile.
  • capsule::reproduce_lib() - build the local library from the lockfile.

It's an renv in the end

A capsule is an renv. The full power of renv can always be used to manipulate the lockfile and library if you wish.

More Repositories

1

datapasta

On top of spaghetti, all covered in cheese....
R
874
star
2

breakerofchains

Break your chain at the cursor line. Run the first bit. See the output. Be free.
R
149
star
3

gistfo

Turn your RStudio untitled tabs into gists. You monsters.
R
140
star
4

paint

paint the data
R
136
star
5

friendlyeval

A friendly interface to tidyeval/rlang that will excuse itself when you're done.
R
107
star
6

fnmate

A function definition generator.
R
94
star
7

tflow

An opinionated lightweight template for smooth targets flows.
R
83
star
8

dflow

Automatically setup a drake project
R
80
star
9

markdrive

Edit Google docs in Markdown with a little help from #rstats
R
71
star
10

slippymath

R functions for dealing with slippy map tile servers.
R
65
star
11

esscss

This repository collects links to ESS configurations shared by #rstats community members.
57
star
12

packup

Collect, stow, and alphabetise library() calls in your R files.
R
57
star
13

deplearning

Detect, install and update R source dependencies.
R
52
star
14

rmdgh

Put Github in your Rmd and Rmd in your GitHub
R
52
star
15

vsconfig

My config for R in VSCode
R
47
star
16

inlegend

Styling for inset ggplot2 map legends
R
41
star
17

nycr_meetup_talk

That Feeling of Workflowing
39
star
18

wisegroup

Now I am become death, destroyer of groups....
R
39
star
19

portal

move data between R processes
R
35
star
20

git_4_sci

A 3.5 hour introduction to basic shell and git/GitHub workflow for ACMES researchers.
CSS
28
star
21

really_useful_engines

R
23
star
22

rmdocs

browse help files as Rmarkdown documents
R
19
star
23

mufflr

Experimental RStudio addins for pipe and assign.
R
19
star
24

mvtview

a Mapbox vector tile server and viewer for R
R
15
star
25

flippingtables

turn the tables on data.frame printing
R
14
star
26

mmmisc

My Library of R Helpers
R
14
star
27

rstudioconf_talk

my rstudio conf talk
R
12
star
28

RmdComment

A simple comment CSS for linking in R markdown
R
11
star
29

hexbin_qld

An example of hexbinning for mapping using {h3jsr}, {dplyr}, {sf}, and {mapdeck}
R
10
star
30

milesmcbain.com

Seeing if I can make my website look any good with distill...
HTML
9
star
31

chradle

A bare bones #rstats test harness for Chrome/Chromium
R
7
star
32

tidycourse

An introduction to the tidyverse for R users. First delivery RezBaz 2017, Brisbane.
R
7
star
33

covid19

some analysis of covid19
R
6
star
34

tidy_aus_ssm

Scrubadubdub
R
6
star
35

shist

Shifting histograms - they're the shist
R
6
star
36

ghost_https_R_blog

A docker-compose.yml for an R blogger using Ghost
6
star
37

burgr_package_discovery

A short talk on ways I discover R packages, and R package stats.
CSS
5
star
38

noprobs

Tidy error data
R
5
star
39

remodel

Turn that LaTeX frown upsidedown.
R
5
star
40

shiny_SMILE

A Shiny web interface to SMILE Bayesian Networks
R
4
star
41

null_island

A stab at communicating science with VR for Bayes on the beach 2017
JavaScript
4
star
42

vr_vs_sp

Spatial meets VR with a little help from R
HTML
4
star
43

sicp_notes

SICP notes and exercises
HTML
3
star
44

lackadaisical

experments with unit testing for lazy people
3
star
45

AMSI_2017_MSBD_Talk

My personal opinions on things that are useful to know about when moving into the discipline of big data.
HTML
3
star
46

git_workshop

An introduction to git for me
3
star
47

mmstyle

My rstats code formatter
R
2
star
48

drake_make

makefile as drake plan
R
2
star
49

haircut

Give your strings a haircut with tidyverse-friendly regex.
R
2
star
50

mbtiles_example

code from my vector tiles blog post
R
2
star
51

mesh_all_the_things

Mesh all the things
R
2
star
52

unmacify_vscode

making my vscode on Mac work the same as Windows and Linux
R
1
star
53

recover_demo

stop() take a breath and recover()
R
1
star
54

MXB344

Course Materials and Assignments for MXB344
HTML
1
star
55

old_blog_source

Blogdown Source for GitHub pages site.
HTML
1
star
56

aus_ssm_census

Overlaying 2016 Census Data on the 2017 Same Sex Marriage Postal Vote
R
1
star
57

r2vr2_meshes_in_webvr

R
1
star
58

keras_facial_keypoints

A quick and dirty test of R's Keras with the Kaggle Facial keypoints data.
R
1
star
59

journalr

A repository for my proposal for an R code/data journalling tool.
HTML
1
star
60

servethis

Serve the current folder on a webserver using whatever Python is available
Shell
1
star
61

packrat_demo

An example repo using a lightweight workflow for dependency management with packrat
HTML
1
star
62

nycr_meetup_talk_code

Coded live in my talk at the New York Open Statistical Programming Meetup
R
1
star
63

r2vr3_shading

Part three of the #r2vr series. Shading a mesh.
R
1
star
64

burgr_20170913_github

Some notes for my presentation about git/github
CSS
1
star
65

r2vr1_uluru_mesh

Repository for code and data described in: `R2VR: Meshing Uluru From Polygons and Rasters`
R
1
star
66

juicr

R
1
star
67

atcursor

Get the thing at the cursor using rstudioapi
R
1
star