Skip to content

Commit 3599815

Browse files
committed
Merge branch 'master' into f-cache-pre
2 parents 156f9be + e7562f1 commit 3599815

File tree

67 files changed

+792
-183
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+792
-183
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ revdep
2020
^\.github/$
2121
^touchstone$
2222
^\.github$
23+
^LICENSE\.md$

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: styler
33
Title: Non-Invasive Pretty Printing of R Code
4-
Version: 1.3.2.9000
4+
Version: 1.4.0.9000
55
Authors@R:
66
c(person(given = "Kirill",
77
family = "Müller",
@@ -13,7 +13,7 @@ Authors@R:
1313
email = "[email protected]"))
1414
Description: Pretty-prints R code without changing the user's formatting
1515
intent.
16-
License: GPL-3
16+
License: MIT + file LICENSE
1717
URL: https://github.com/r-lib/styler, https://styler.r-lib.org
1818
BugReports: https://github.com/r-lib/styler/issues
1919
Imports:
@@ -46,7 +46,7 @@ Encoding: UTF-8
4646
LazyData: true
4747
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate",
4848
"pkgapi::api_roclet"))
49-
RoxygenNote: 7.1.1
49+
RoxygenNote: 7.1.1.9001
5050
Collate:
5151
'addins.R'
5252
'communicate.R'

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2021
2+
COPYRIGHT HOLDER: styler authors

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2021 styler authors
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NEWS.md

Lines changed: 85 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,126 @@
1-
# styler 1.3.2.9000 (Development)
1+
# styler 1.4.0.9000 (Development)
2+
3+
*No news yet*
4+
5+
# styler 1.4.0
26

37
## API Changes
48

5-
- `style_file()` and friends gain argument `dry` to control if changes should
6-
be applied to files or not (#634).
9+
**new**
10+
11+
- `style_file()` and friends gain argument `dry` to control if changes should be
12+
applied to files or not (#634).
713

814
- `style_file()` and friends gain argument `base_indention` (defaulting to 0) to
9-
control by how much the output code is indented (#649, #692). The Addin for
10-
styling a selection picks that up, e.g. you can style a function body and
15+
control by how much the output code is indented (#649, #692). The Addin for
16+
styling a selection picks that up, e.g. you can style a function body and
1117
indention is preserved (#725).
12-
13-
- added an option (`styler.test_dir_writeable`) that changes test behavior
14-
to not directly modify test files in the current directory (#548).
1518

1619
- added an option for disabling all communication when using the package
1720
(`styler.quiet`) (#640).
1821

1922
- `scope` in `tidyverse_style()` can now be specified with higher granularity
20-
through `I()`, e.g. `I(c('spaces', 'tokens'))` allows us to style spaces and
21-
tokens without styling line breaks and indention. Previously, only a string
22-
was allowed and all less invasive scopes were included, e.g. if you wanted to
23-
style tokens, you had to always also style spaces, indention, line breaks as
23+
through `I()`, e.g. `I(c('spaces', 'tokens'))` allows us to style spaces and
24+
tokens without styling line breaks and indention. Previously, only a string
25+
was allowed and all less invasive scopes were included, e.g. if you wanted to
26+
style tokens, you had to always also style spaces, indention, line breaks as
2427
well (#705, #707).
2528

26-
- New argument `transformers_drop` in `create_style_guide()` to be populated with
27-
new helper function `specify_transformers_drop()` for specifying conditions
28-
under which transformers are not going to be used and can therefore be
29-
omitted without effecting the result of styling (#711).
29+
- added an option (`styler.test_dir_writeable`) that changes test behavior to
30+
not directly modify test files in the current directory (#548).
31+
32+
- New argument `transformers_drop` in `create_style_guide()` to be populated
33+
with new helper function `specify_transformers_drop()` for specifying
34+
conditions under which transformers are not going to be used and can therefore
35+
be omitted without effecting the result of styling (#711).
36+
37+
**deprecated**
38+
39+
- The environment variable `save_after_styling` is deprecated in favor of the R
40+
option `styler.save_after_styling` to control if a file is saved after styling
41+
with the RStudio Addin. Note than in RStudio >= 1.3.0, you can auto-save edits
42+
in general (Code -> Saving -> Auto-Save), e.g. on idle editor or focus loss,
43+
so this feature becomes less relevant (#631, #726).
44+
3045

3146
## Major changes
3247

33-
- Documentation overhaul: New README, new "Get started" pkgdown page, new
34-
vignettes on `strict = FALSE`, `Adoption` renamed to
35-
`Third-party integrations`, minor other consistency edits.
36-
- The environment variable `save_after_styling` is deprecated in favor of
37-
the R option `styler.save_after_styling` to control if a file is saved after
38-
styling with the RStudio Addin. Note than in RStudio >= 1.3.0, you can
39-
auto-save edits in general (Code -> Saving -> Auto-Save), e.g. on idle editor
40-
or focus loss, so this feature becomes less relevant (#631, #726).
41-
- blank lines in function calls and headers are now removed, for the former only
42-
when there are no comments before or after the blank line (#629, #630, #635,
48+
- styler is now distributed under the MIT license (#751).
49+
50+
- Documentation overhaul: New README, new "Get started" pkgdown page, new
51+
vignettes on `strict = FALSE`, `Adoption` renamed to `Third-party
52+
integrations` (#741), adding search to pkgdown (#623), group functions in
53+
pkgdown reference page (#625), minor other doc improvements (#643, #618, #614,
54+
#677, #651, #667, #672, #687, #752, #754).
55+
56+
- `@exampleIsf` roxygen tag for conditional examples is now supported (#743).
57+
58+
- blank lines in function calls and headers are now removed, for the former only
59+
when there are no comments before or after the blank line (#629, #630, #635,
4360
#723).
44-
- speed improvements: ~10% when cache is activated because transformers are not
45-
captured as character anymore (#679), ~3% in low-level optimization (#691).
46-
7% by requiring magrittr 2.0 (#681), ~8% by dropping unused transformers
47-
(#711), 4% by avoiding unnecessary sorting in internals (#739).
48-
- `#<<` is now recognized as the xaringan marker and no space is added after`#`
61+
62+
- speed improvements: 15% faster on new code, 70% on repeated styling of
63+
compliant code (The latter is not so relevant because it was almost
64+
instantaneous already). Most relevant contributions were #679, #691, #681,
65+
#711, #739.
66+
67+
- `#<<` is now recognized as the xaringan marker and no space is added after`#`
4968
(#700).
5069

5170
## Minor changes and fixes
5271

53-
- `style_dir()` and `style_pkg()` now apply directory exclusion recursively with
72+
- `style_dir()` and `style_pkg()` now apply directory exclusion recursively with
5473
`exclude_dirs` (#676).
55-
- `switch()` now has line breaks after every argument to match the tidyverse
74+
75+
- `switch()` now has line breaks after every argument to match the tidyverse
5676
style guide (#722, #727).
57-
- unary `+` before a function call does not give an error anymore, as before
77+
78+
- unary `+` before a function call does not give an error anymore, as before
5879
version 1.3.0 (#697).
59-
- certain combinations of `stylerignore` markers and cached expressions now
80+
81+
- certain combinations of `stylerignore` markers and cached expressions now
6082
don't give an error anymore (#738).
83+
6184
- cache is now correctly invalidated when style guide arguments change (#647).
85+
6286
- empty lines are now removed between pipes and assignments (#645, #710).
63-
- overhaul pgkdown site: Add search (#623), group function in Reference (#625).
87+
88+
- multiple `@examples` roxygen tags in a code block of `#'` are no longer
89+
squashed (#748).
90+
91+
- roxygen code examples starting on the same line as the `@examples` tag are no
92+
longer moved to the next line (#748).
93+
6494
- always strip trailing spaces and make cache insensitive to it (#626).
65-
- `style_text()` can now style all input that `is.character()`, not just if it
95+
96+
- `style_text()` can now style all input that `is.character()`, not just if it
6697
inherits from classes `character`, `utf8` or `vertical` (#693).
98+
6799
- logical operators within square braces are now moved from the start of a line
68100
to the end of the previous line (#709).
101+
69102
- spaces are now removed before `[` and `[[` (#713).
70-
- minor documentation improvements (#643, #618, #614, #677, #651, #667, #672,
71-
#687).
72-
- The internal `create_tree()` only used in testing of styler now works when the
103+
104+
- The internal `create_tree()` only used in testing of styler now works when the
73105
cache is activated (#688).
106+
74107
- simplification of internals (#692).
75-
- include `test-*` files in styling pre-commit hook (#724).
76108

77109
## Infrastructure changes
78110

79111
- switched from travis and AppVeyor to GitHub Actions (#653, #660).
80-
- Added basic continuous benchmarking with [lorenzwalthert/touchstone](https://github.com/lorenzwalthert/touchstone)
112+
113+
- Added basic continuous benchmarking with
114+
[lorenzwalthert/touchstone](https://github.com/lorenzwalthert/touchstone)
81115
(#674, #684, #698).
82116

117+
- include `test-*` files in styling pre-commit hook (#724).
118+
119+
120+
Thanks to all the people who made this release possible:
121+
122+
[&#x0040;assignUser](https://github.com/assignUser), [&#x0040;ColmanHumphrey](https://github.com/ColmanHumphrey), [&#x0040;davidchall](https://github.com/davidchall), [&#x0040;espinielli](https://github.com/espinielli), [&#x0040;giko45](https://github.com/giko45), [&#x0040;hadley](https://github.com/hadley), [&#x0040;IndrajeetPatil](https://github.com/IndrajeetPatil), [&#x0040;intiben](https://github.com/intiben), [&#x0040;jamespeapen](https://github.com/jamespeapen), [&#x0040;jthomasmock](https://github.com/jthomasmock), [&#x0040;Kalaschnik](https://github.com/Kalaschnik), [&#x0040;kevinushey](https://github.com/kevinushey), [&#x0040;krlmlr](https://github.com/krlmlr), [&#x0040;lcolladotor](https://github.com/lcolladotor), [&#x0040;MichaelChirico](https://github.com/MichaelChirico), [&#x0040;michaelquinn32](https://github.com/michaelquinn32), [&#x0040;mine-cetinkaya-rundel](https://github.com/mine-cetinkaya-rundel), [&#x0040;pat-s](https://github.com/pat-s), [&#x0040;PMassicotte](https://github.com/PMassicotte), [&#x0040;QuLogic](https://github.com/QuLogic), [&#x0040;renkun-ken](https://github.com/renkun-ken), [&#x0040;RichardJActon](https://github.com/RichardJActon), [&#x0040;seed-of-apricot](https://github.com/seed-of-apricot), [&#x0040;select-id-from-users](https://github.com/select-id-from-users), [&#x0040;SimonDedman](https://github.com/SimonDedman), [&#x0040;stefanoborini](https://github.com/stefanoborini), [&#x0040;swsoyee](https://github.com/swsoyee), and [&#x0040;Winterstorm-j](https://github.com/Winterstorm-j).
123+
83124
# styler 1.3.2
84125

85126
Release upon request by the CRAN team.
@@ -172,7 +213,7 @@ Thanks to all contributors involved, in particular
172213
[&#x0040;davidski](https://github.com/davidski),
173214
[&#x0040;IndrajeetPatil](https://github.com/IndrajeetPatil),
174215
[&#x0040;pat-s](https://github.com/pat-s), and
175-
[&#x0040;programming-wizard](https://github.com/programming-wizard).
216+
[&#x0040;programming-wizard](https://github.com).
176217

177218
# styler 1.2.0
178219

@@ -297,7 +338,7 @@ else you can use styler functionality:
297338
frames with `drake::drake_plan_source()`.
298339

299340
* Adding styler as a fixer to the [ale
300-
Plug-in](https://github.com/w0rp/ale/pull/2401#issuecomment-485942966) for
341+
Plug-in](https://github.com/dense-analysis/ale/pull/2401) for
301342
VIM.
302343

303344
Thanks to all contributors involved, in particular

R/roxygen-examples-add-remove.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,19 @@ remove_roxygen_mask <- function(text) {
2929
#' #' @examples c(1, 2)
3030
#' @keywords internal
3131
remove_roxygen_header <- function(text) {
32-
text <- gsub("^\\s*@examples\\s*", "", text, perl = TRUE)
33-
starts_with_blank <- text[1] == "\n"
34-
c(text[1][!starts_with_blank], text[-1])
32+
gsub("^[\\s\t]*@examples(If)?(\\s|\t)*", "", text, perl = TRUE)
3533
}
3634

35+
#' Add the roxygen mask to code
36+
#'
37+
#' @param text Character vector with code.
38+
#' @param example_type Either 'examples' or 'examplesIf'.
39+
#' @keywords internal
3740
#' @importFrom purrr map2_chr
38-
add_roxygen_mask <- function(text) {
41+
add_roxygen_mask <- function(text, example_type) {
3942
space <- ifelse(text == "", "", " ")
40-
c(paste0("#' @examples"), map2_chr(space, text, ~ paste0("#'", .x, .y)))
43+
c(
44+
paste0("#' @", example_type, space[1], text[1]),
45+
map2_chr(space[-1], text[-1], ~ paste0("#'", .x, .y))
46+
)
4147
}

R/roxygen-examples-find.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#' @importFrom rlang seq2
88
#' @keywords internal
99
identify_start_to_stop_of_roxygen_examples_from_text <- function(text) {
10-
starts <- grep("^#'\\s*@examples", text, perl = TRUE)
10+
starts <- grep("^#'(\\s|\t)*@examples(If\\s|\\s|\t|$)", text, perl = TRUE)
1111
if (length(starts) < 1L) {
1212
return(integer())
1313
}
14-
stop_candidates <- grep("^[^#]|^#'\\s*@", text, perl = TRUE)
14+
stop_candidates <- grep("(^[^#]|^#'[\\s\t]*@)", text, perl = TRUE)
1515
stops <- map(starts, match_stop_to_start, stop_candidates) %>%
1616
flatten_int()
1717
if (length(stops) < 1L) {

R/roxygen-examples-parse.R

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#' ))
1616
#' @keywords internal
1717
parse_roxygen <- function(roxygen) {
18-
connection <- textConnection(emulate_rd(roxygen))
18+
emulated <- emulate_rd(roxygen)
19+
connection <- textConnection(emulated$text)
1920
had_warning <- FALSE
2021
parsed <- withCallingHandlers(
2122
{
@@ -31,9 +32,8 @@ parse_roxygen <- function(roxygen) {
3132
invokeRestart("muffleWarning")
3233
}
3334
)
34-
is_line_break <- parsed[1] == "\n"
3535
close(connection)
36-
c(parsed[1][!is_line_break], parsed[-1])
36+
list(text = parsed, example_type = emulated$example_type)
3737
}
3838

3939
#' Fix [tools::parse_Rd()] output
@@ -124,22 +124,30 @@ roxygen_remove_extra_brace <- function(parsed) {
124124
#' `remove_roxygen_mask()` when there are no characters to escape.
125125
#' @keywords internal
126126
emulate_rd <- function(roxygen) {
127+
example_type <- gsub("^#'(\\s|\t)*@examples(If)?(\\s|\t)*(.*)", "examples\\2", roxygen[1])
127128
if (needs_rd_emulation(roxygen)) {
128129
roxygen <- c(
129-
"#' Example", "#' @examples",
130-
gsub("^#'\\s*@examples\\s*(.*)", "#' \\1", roxygen),
130+
"#' Example",
131+
gsub("^#'(\\s|\t)*@examples(If)?(\\s|\t)*(.*)", "#' @examples \\4", roxygen),
131132
"x <- 1"
132133
)
133-
134-
roxygen2::roc_proc_text(
134+
text <- roxygen2::roc_proc_text(
135135
roxygen2::rd_roclet(),
136136
paste(roxygen, collapse = "\n")
137137
)[[1]]$get_section("examples") %>%
138138
as.character() %>%
139139
.[-1]
140+
text <- c(
141+
if (grepl("^#'(\\s|\t)*@examples(\\s|\t)*$", roxygen[2])) "",
142+
text
143+
)
140144
} else {
141-
remove_roxygen_mask(roxygen)
145+
text <- remove_roxygen_mask(roxygen)
142146
}
147+
list(
148+
text = text,
149+
example_type = example_type
150+
)
143151
}
144152

145153
#' Check if rd emulation is required with [roxygen2::roc_proc_text()]

R/roxygen-examples.R

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,28 @@
99
#' @importFrom purrr map flatten_chr
1010
#' @keywords internal
1111
style_roxygen_code_example <- function(example, transformers, base_indention) {
12-
bare <- parse_roxygen(example)
13-
one_dont <- split(bare, factor(cumsum(bare %in% dont_keywords())))
12+
example <- split(example, cumsum(grepl("^#' *@examples", example))) # TODO can this handle @examples 1
13+
purrr::map(
14+
example, style_roxygen_code_example_one,
15+
transformers = transformers, base_indention = base_indention
16+
) %>%
17+
flatten_chr()
18+
}
19+
20+
#' Style a roxygen code example with exactly one `@example` or `@exampleIf`
21+
#' @inheritParams style_roxygen_code_example
22+
#' @param example_one A character vector, one element per line, that contains in
23+
#' total at most one example tag.
24+
#' @keywords internal
25+
style_roxygen_code_example_one <- function(example_one, transformers, base_indention) {
26+
bare <- parse_roxygen(example_one)
27+
one_dont <- split(bare$text, factor(cumsum(bare$text %in% dont_keywords())))
1428
map(one_dont, style_roxygen_code_example_segment,
1529
transformers = transformers,
1630
base_indention = base_indention
1731
) %>%
1832
flatten_chr() %>%
19-
add_roxygen_mask()
33+
add_roxygen_mask(bare$example_type)
2034
}
2135

2236
#' Style a roxygen code example segment

R/rules-line-breaks.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ style_line_break_around_curly <- function(strict, pd) {
122122
#' With \{rlang\} version 0.4, a new syntactic sugar is introduced, the
123123
#' curly-curly operator. It interprets this code in a special way:
124124
#' `call(\{\{ x \}\})`. See this
125-
#' [blog post](https://www.tidyverse.org/articles/2019/06/rlang-0-4-0/)
125+
#' [blog post](https://www.tidyverse.org/blog/2019/06/rlang-0-4-0/)
126126
#' on the topic. Here, the curly-curly sugar is understood as two opening
127127
#' curly braces, followed by an expression followed by two closing curly braces,
128128
#' e.g. `\{\{1\}\}`. `\{\{1\} + 1\}` does not contain the curly-curly syntactic

0 commit comments

Comments
 (0)