Home

Awesome

codegrip

<!-- badges: start -->

Codecov test coverage R-CMD-check

<!-- badges: end -->

codegrip provides RStudio addins and Emacs commands for reshaping R code and navigating across syntactic constructs.

Reshaping

addin_reshape lets you cycle between different shapes of function calls. For instance, reshaping transforms code from wide to long shape and vice versa.

<img src="man/figures/README/reshape-call.svg"/>

Note that for function definitions, addin_reshape cycles through two different long shapes. The traditional L form uses more horizontal space whereas the flat form uses less horizontal space and the arguments are always aligned at single indent:

<img src="man/figures/README/reshape-def.svg"/>

Navigating

There are currently two motions implemented in codegrip: outwards and inwards.

<img src="man/figures/README/move.svg"/>

These motions are handy for quick navigation across to quickly jump from a function argument to the corresponding function call. From there, you can reshape the whole call using addin_reshape.

<img src="man/figures/README/move-reshape.svg"/>

Installation

The package is not yet on CRAN but you can install the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("lionel-/codegrip")

Setup

Suggested keybindings:

Not yet implemented:

Using in Visual Studio Code

addin_reshape is available for keybinding in VS Code. See here for instructions on enabling general addin support.

Once addins are enabled, add the following to keybindings.json:

{
  "key": "Alt+tab",
  "command": "r.runCommand",
  "description": "Reshape expressions longer or wider",
  "when": "editorTextFocus",
  "args": "codegrip::addin_reshape()"
}

Roadmap

Limitations

codegrip currently uses the R parser to figure out the structure of your code. Because of this, it doesn't work with malformed or partially written code. Your whole file must be valid R code for codegrip commands to work.