-
Notifications
You must be signed in to change notification settings - Fork 73
No line break after pipe inserted #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Also related to #74. |
Thanks for considering old issues @msberends. The paragraph in tidyvese/style that proposed single-line pipes (linked to #74) has been weakened in my eyes so I think for |
Any news? |
Yes, I just saw it the other day. I think we can do it before we release 1.1.1, i..e within the next 10 days. |
For now, this is what I use (and others can): style_with_pipe <- function () {
context <- rstudioapi::getConsoleEditorContext()
text <- context$selection[[1]]$text
if (all(nchar(text) == 0)) {
# try source editor
context <- rstudioapi::getSourceEditorContext()
text <- context$selection[[1]]$text
}
if (all(nchar(text) == 0)) {
stop("No code selected")
}
# replace pipes
text <- gsub("( |\n)*%>%( |\n)*", " %>%\n", text)
# line after comma, will else be too cluttered
text <- gsub(' ?, ?', ',\n', text)
# do everything else defined by styler::style_text
out <- styler::style_text(text)
# don't put brackets on new lines on their own, and remove empty lines
toinsert <- paste0(out[out != ""], collapse = "\n")
toinsert <- gsub(" *\n *[)]",")", toinsert)
rstudioapi::modifyRange(location = context$selection[[1]]$range,
text = toinsert,
id = context$id)
} |
I was quite surprised to learn that
leads to
and not something like
So pipes are not followed by a line break. I looked at http://styler.r-lib.org/articles/introducing_styler.html and https://lorenzwalthert.netlify.com/post/customizing-styler-the-quick-way/ how the tidyverse default style is being applied, and I don't see anything resembling the proposed style on https://style.tidyverse.org/pipes.html#whitespace:
Isn't or shouldn't this be the default behaviour of
styler::tidyverse_style()
?? Can I change this behaviour?The text was updated successfully, but these errors were encountered: