Atom with easy indentation for piping R code blocks with dplyr and ggplot2
This is a fork of Distuin Speckhals' python-indent
R Indent is the indentation behavior you've been waiting for in Atom! You should no longer
have to worry about mashing your tab/space/backspace key every time you press enter
in the middle
of coding. Also, compared to other editors, there is no need to change an app configuration if you
want to have a mixture of different types of indents (namely hanging and opening-delimiter-aligned).
A main obstacle with Atom's native indentation behavior is that it doesn't yet have the necessary
API's to do line up R code chunks when using pipes %>%
or using the +
sign to put together lines of ggplot code. In addition, when using lots of arguments in a function, it is generally recommended that all arguments are
aligned with the opening delimiter, which Atom's native indentation
does not recognize.
- language-python - Auto indent on line continuation with list/tuple
- atom - Autoindent not working properly
This package was made to give you expected indentation behavior; r-indent listens for
editor:newline
events in R source files, and when triggered, adjusts the indentation to
be lined up relative to the opening delimiter of the statement or "hanging" (for parameters,
tuples, or lists).
f <- function(longarg1,
longarg2, # would have to mash space to get longarg2 here
longarg3){
# } <- this is where the closed bracket wants to go
#<--properly dedents to here
}
Without the r-indent package, the second argument would not have been indented to line up with the first. In addition, the closed bracket would have been lined up with the arguments, since Atom sets the indentation level to the second argument after you have mashed the tab/space bar to line it up with the first argument.
This package should also give you correct indentation if you are piping together ggplot code
plot <-
ggplot(df) +
geom_point()
#<--properly dedents to here
or using the piping in the dplyr package
### One way
df <-
df %>%
select() %>%
mutate()
#<--properly dedents to here
### Another way
df <- df %>%
select() %>%
mutate()
#<--properly dedents to here
after pressing enter at the end of both of these commands, the r-indent package will take your cursor to the indentation of the line that started these chained blocks of code, rather than continue with the current indentation.
- Come up with more examples
- Update testing
- Clean up and comment code
There are plenty of other examples for Python (not R yet) (ordinary and extraordinary) in the test_file.