Skip to content

Commit 016e776

Browse files
Merge pull request #435 from lorenzwalthert/eol-addin
- Addin fix (#435).
2 parents 34f82cd + 240a2dd commit 016e776

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

R/addins.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ style_active_file <- function() {
3333
}
3434
rstudioapi::modifyRange(
3535
c(1, 1, length(context$contents) + 1, 1),
36-
paste0(append(out, ""), collapse = "\n"),
36+
paste0(ensure_last_is_empty(out), collapse = "\n"),
3737
id = context$id
3838
)
3939
if (Sys.getenv("save_after_styling") == TRUE && context$path != "") {

R/utils.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ line_col_names <- function() {
44
c("line1", "line2", "col1", "col2")
55
}
66

7+
ensure_last_is_empty <- function(x) {
8+
has_line_break_at_eof <- x[length(x)] == ""
9+
if (has_line_break_at_eof) {
10+
return(x)
11+
} else {
12+
append(x, "")
13+
}
14+
}
15+
716
#' Check whether two columns match
817
#'
918
#' @param col1,col2 Column names as string.

README.Rmd

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ styler can be customized to format code according to other style guides too.
3131

3232
## Installation
3333

34-
You can install the package from CRAN:
34+
You can install the package from CRAN:
3535

3636
```{r, eval = FALSE}
3737
install.packages("styler")
3838
```
3939

40-
Or get the development version from GitHub:
40+
Or get the development version from GitHub:
4141

4242
```{r, eval = FALSE}
4343
# install.packages("remotes")
@@ -106,10 +106,10 @@ style_text(
106106

107107
This was just the tip of the iceberg. Learn more about customization with the
108108
tidyverse style guide in in this
109-
[vignette](http://styler.r-lib.org/articles/introducing_styler.html). If this
110-
is not flexible enough for you, you can implement your own style guide, as
111-
explained in the corresponding
112-
[vignette](http://styler.r-lib.org/articles/customizing_styler.html)
109+
[vignette](http://styler.r-lib.org/articles/introducing_styler.html). If this is
110+
not flexible enough for you, you can implement your own style guide, as
111+
explained in the corresponding
112+
[vignette](http://styler.r-lib.org/articles/customizing_styler.html).
113113

114114
## Adaption of styler
115115

@@ -118,21 +118,28 @@ styler functionality is made available through other packages, most notably
118118
* `usethis::use_tidy_style()` styles your project according to the tidyverse
119119
style guide.
120120
* `reprex::reprex(style = TRUE)` to prettify reprex code before printing. To
121-
permanently use `style = TRUE` without specifying it every time, you can
122-
add the following line to your `.Rprofile` (via `usethis::edit_r_profile()`):
121+
permanently use `style = TRUE` without specifying it every time, you can add the
122+
following line to your `.Rprofile` (via `usethis::edit_r_profile()`):
123123
`options(reprex.styler = TRUE)`.
124+
* you can pretty-print your R code in RMarkdown reports without having styler
125+
modifying the source. This feature is implemented as a code chunk option in
126+
knitr. use `tidy = "styler"` in the header of a code chunks (e.g. ` ```{r
127+
name-of-the-chunk, tidy = "styler"}`), or `knitr::opts_chunk$set(tidy =
128+
"styler")` at the top of your RMarkdown script.
129+
* pretty-printing of [drake](https://github.com/ropensci/drake) workflow data
130+
frames with `drake::drake_plan_source()`.
124131

125132
## Further resources
126133

127-
* The official [web documentation](http://styler.r-lib.org/) of styler,
128-
containing various vignettes function documentation as well as a change-log.
129-
* [Blog
130-
post](https://lorenzwalthert.netlify.com/posts/customizing-styler-the-quick-way/)
134+
* The official [web documentation](http://styler.r-lib.org/) of styler,
135+
containing various vignettes function documentation as well as a change-log.
136+
* [Blog
137+
post](https://lorenzwalthert.netlify.com/posts/customizing-styler-the-quick-way/)
131138
about how you can customize styler without being an expert.
132139
* A [tidyverse.org blog
133-
post](https://www.tidyverse.org/articles/2017/12/styler-1.0.0/) introducing
134-
the functionality of styler.
135-
* The wiki of [Google Summer of Code
140+
post](https://www.tidyverse.org/articles/2017/12/styler-1.0.0/) introducing the
141+
functionality of styler.
142+
* The wiki of [Google Summer of Code
136143
2017](https://github.com/rstats-gsoc/gsoc2017/wiki/Noninvasive-source-code-formatting)
137144
or the [pkgdown](https://r-lib.github.io/styler/) page contain information
138145
related to the initial development phase during Google Summer of Code 2017.

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ with the tidyverse style guide in in this
104104
[vignette](http://styler.r-lib.org/articles/introducing_styler.html). If
105105
this is not flexible enough for you, you can implement your own style
106106
guide, as explained in the corresponding
107-
[vignette](http://styler.r-lib.org/articles/customizing_styler.html)
107+
[vignette](http://styler.r-lib.org/articles/customizing_styler.html).
108108

109109
## Adaption of styler
110110

@@ -117,6 +117,14 @@ notably
117117
printing. To permanently use `style = TRUE` without specifying it
118118
every time, you can add the following line to your `.Rprofile` (via
119119
`usethis::edit_r_profile()`): `options(reprex.styler = TRUE)`.
120+
- you can pretty-print your R code in RMarkdown reports without having
121+
styler modifying the source. This feature is implemented as a code
122+
chunk option in knitr. use `tidy = "styler"` in the header of a code
123+
chunks (e.g. ` ```{r name-of-the-chunk, tidy = "styler"}`), or
124+
`knitr::opts_chunk$set(tidy = "styler")` at the top of your
125+
RMarkdown script.
126+
- pretty-printing of [drake](https://github.com/ropensci/drake)
127+
workflow data frames with `drake::drake_plan_source()`.
120128

121129
## Further resources
122130

0 commit comments

Comments
 (0)