• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    R
  • License
    Other
  • Created almost 4 years ago
  • Updated about 2 years ago

Reviews

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

Repository Details

Break your chain at the cursor line. Run the first bit. See the output. Be free.

breakerofchains

R-CMD-check Lifecycle: stable

Break your chain at the cursor line. Run the first bit. See the output. Be free.

Installation

# install.packages("remotes")
remotes::install_github("MilesMcBain/breakerofchains")

Usage

Say you had:

library(tidyverse)

star_plot <-
  starwars %>%
  group_by(species, sex) %>%
  select(height, mass) %>%
  summarise(
    height = mean(height, na.rm = TRUE),
    mass = mean(mass, na.rm = TRUE)
  ) %>%
  ggplot(aes(x = height, y = mass)) +
  geom_point()
  1. Pop your cursor on line you want to run up to. e.g. select(height, mass).

  2. Invoke the RStudio Addin Break chain and run to cursor

  3. Code is run from start of chain up to your cursor line, and result is printed in the console:

starwars %>%
  group_by(species, sex) %>%
  select(height, mass)
#> Adding missing grouping variables: `species`, `sex`
#> # A tibble: 87 × 4
#> # Groups:   species, sex [41]
#>    species sex    height  mass
#>    <chr>   <chr>   <int> <dbl>
#>  1 Human   male      172    77
#>  2 Droid   none      167    75
#>  3 Droid   none       96    32
#>  4 Human   male      202   136
#>  5 Human   female    150    49
#>  6 Human   male      178   120
#>  7 Human   female    165    75
#>  8 Droid   none       97    32
#>  9 Human   male      183    84
#> 10 Human   male      182    77
#> # … with 77 more rows

with a stored result available in .chain:

glimpse(.chain)
#> Rows: 87
#> Columns: 4
#> Groups: species, sex [41]
#> $ species <chr> "Human", "Droid", "Droid", "Human", "Human", "Human", "Human",…
#> $ sex     <chr> "male", "none", "none", "male", "female", "male", "female", "n…
#> $ height  <int> 172, 167, 96, 202, 150, 178, 165, 97, 183, 182, 188, 180, 228,…
#> $ mass    <dbl> 77.0, 75.0, 32.0, 136.0, 49.0, 120.0, 75.0, 32.0, 84.0, 77.0, …

For pipe chains Base pipe |> is supported, but chains can also be broken at lines ending in any %% infix, and any math/logic infix. So you can break ggplot2 layers chained with + this way too.

Stored result .chain

By default the result of the last broken chain is saved in your environment as the variable .chain so you can immediately start passing it to further diagnostics. I’ve found this is nicer than .Last.value which is easy to accidentally overwrite, and has a hard to remember the capitalisation scheme.

Disable this behaviour with options(breakerofchains_store_result = FALSE)

Keybindings

[
    {
        "description": "run breakerofchains",
        "key": "ctrl+shift+b",
        "command": "r.runCommand",
        "when": "editorTextFocus",
        "args": "breakerofchains::break_chain()"
    },
]

Pitfalls

Since R’s parser is used to help figure out where the chain starts, the process will fail if any of the code above the cursor is invalid - even code not in the chain.

For Rmd documents only code in the current chunk is parsed.

Extending it yourself

break_chain() returns the result of the chain evaluation invisibly, so you can build your own shortcuts that do something with the result other than print it to the console. E.g. View(break_chain()) See break_chain and NEWS.md for more info.

More Repositories

1

datapasta

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

capsule

An inversion of renv for low effort reproducible R package libraries
R
143
star
3

gistfo

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

paint

paint the data
R
137
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
93
star
7

tflow

An opinionated lightweight template for smooth targets flows.
R
87
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
24
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

flippingtables

turn the tables on data.frame printing
R
16
star
25

mvtview

a Mapbox vector tile server and viewer for R
R
16
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

milesmcbain.com

Seeing if I can make my website look any good with distill...
HTML
10
star
30

hexbin_qld

An example of hexbinning for mapping using {h3jsr}, {dplyr}, {sf}, and {mapdeck}
R
10
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

shist

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

ghost_https_R_blog

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

tidy_aus_ssm

Scrubadubdub
R
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

vr_vs_sp

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

null_island

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

sicp_notes

SICP notes and exercises
HTML
3
star
44

lackadaisical

experments with unit testing for lazy people
3
star
45

git_workshop

An introduction to git for me
3
star
46

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
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

burgr_20170913_github

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

unmacify_vscode

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

recover_demo

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

MXB344

Course Materials and Assignments for MXB344
HTML
1
star
56

old_blog_source

Blogdown Source for GitHub pages site.
HTML
1
star
57

aus_ssm_census

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

r2vr2_meshes_in_webvr

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

nycr_meetup_talk_code

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

packrat_demo

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

r2vr3_shading

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

keras_facial_keypoints

A quick and dirty test of R's Keras with the Kaggle Facial keypoints data.
R
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

classic_r_project

The classic flavour you know and maybe love
R
1
star
68

atcursor

Get the thing at the cursor using rstudioapi
R
1
star
69

ssa_targets_workshop

A half-day introduction to {targets}
1
star