get_broken_chain: get a broken chain as text

View source: R/chain_break.R

get_broken_chainR Documentation

get a broken chain as text

Description

This interface is intended for developers who want to hook into the chain breaking algorithm to create bindings in other text editors.

Usage

get_broken_chain(doc_lines, doc_cursor_line)

Arguments

doc_lines

a character vector of R code, one element per line.

doc_cursor_line

a number representing the line the cursor is on.

Details

Given a character vector of R code lines, and the line number of the cursor, it returns a character vector of R code lines which is the start of the chained expression the cursor is on, up to the cursor line.

Any assignment with <- or = at the head of the chain is removed.

Value

a character vector of R code representing the broken chain.

Examples

get_broken_chain(
    c(
     "species_scatter <- starwars %>%",
     "group_by(species, sex) %>%",
     "select(height, mass)",
     "    .99s.scatter <- starwars %>%",
     "group_by(species, sex) %>%",
     "select(height, mass)"
    ),
    3
)

MilesMcBain/breakerofchains documentation built on Nov. 23, 2022, 8:53 p.m.