library(dplyr) knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
Break your chain at the cursor line. Run the first bit. See the output. Be free.
# install.packages("remotes") remotes::install_github("MilesMcBain/breakerofchains")
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()
Pop your cursor on line you want to run up to. e.g. select(height, mass)
.
Invoke the RStudio Addin Break chain and run to cursor
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)
.chain <- starwars %>% group_by(species, sex) %>% select(height, mass)
with a stored result available in .chain
:
glimpse(.chain)
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.
.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.json
like:[ { "description": "run breakerofchains", "key": "ctrl+shift+b", "command": "r.runCommand", "when": "editorTextFocus", "args": "breakerofchains::break_chain()" }, ]
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.
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.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.