Giter VIP home page Giter VIP logo

breakerofchains's Introduction

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

breakerofchains's People

Contributors

milesmcbain avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.