Skip to content

Commit 3dbff54

Browse files
Merge pull request #299 from r-lib/r-1.0.0
- merge release 1.0.0 into master (#299).
2 parents cf08eec + 1e57c64 commit 3dbff54

File tree

141 files changed

+361
-2626
lines changed

Some content is hidden

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

141 files changed

+361
-2626
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ CONTRIBUTING.md
1313
^\.gitsum$
1414
^gitsum$
1515

16+
^cran-comments\.md$

API

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Exported functions
44

5-
create_style_guide(initialize = initialize_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
5+
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
6+
default_style_guide_attributes(pd_flat)
67
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
78
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
89
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL)
@@ -12,7 +13,3 @@ style_text(text, ..., style = tidyverse_style, transformers = style(...))
1213
tidyverse_math_token_spacing()
1314
tidyverse_reindention()
1415
tidyverse_style(scope = "tokens", strict = TRUE, indent_by = 2, start_comments_with_one_space = FALSE, reindention = tidyverse_reindention(), math_token_spacing = tidyverse_math_token_spacing())
15-
16-
## Foreign S3 methods
17-
18-
print.vertical(x, ...)

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: styler
2-
Title: Non-invasive Pretty Printing of R code
3-
Version: 0.0-11
2+
Title: Non-Invasive Pretty Printing of R Code
3+
Version: 1.0.0
44
Authors@R: c(person("Kirill", "Müller", role = c("aut"), email = "[email protected]"),
55
person("Lorenz", "Walthert", role = c("cre", "aut"), email = "[email protected]"))
66
Description:

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
S3method(print,vertical)
44
export(create_style_guide)
5+
export(default_style_guide_attributes)
56
export(specify_math_token_spacing)
67
export(specify_reindention)
78
export(style_dir)

NEWS.md

Lines changed: 71 additions & 187 deletions
Original file line numberDiff line numberDiff line change
@@ -1,187 +1,71 @@
1-
## styler 0.0-11 (2017-12-05)
2-
3-
- Remove `regex_none()`, document `NULL` default.
4-
- `style_dir()` and `style_pkg()` now also handle `.Rmd` files (#292, @jonmcalder).
5-
- Add test for styling `.Rmd` files.
6-
- Better error message for styling new files via the RStudio addin (#295).
7-
- Spelling via devtools::spell_check() (#294).
8-
- Roundtrip and CLI (#289).
9-
10-
11-
## styler 0.0-10 (2017-11-27)
12-
13-
- Adapt documentation (#290).
14-
- Add roundtrip (#287).
15-
- Fix AppVeyor builds.
16-
- Fix token insertion / comment interaction (#279).
17-
- Clarify labelling strategy (#285).
18-
- Fixing and extending Rstudioaddins (#283).
19-
- Fix eq assign parsing (#276).
20-
- style_files -> vectorized style_file (#273).
21-
- Refactoring (#270).
22-
- Fix CI (#275).
23-
- Fix covr (#274).
24-
- Renaming files (#271).
25-
- Handle styling of an unsaved active file (#243).
26-
- Test R 3.1 and R 3.2 (#249).
27-
- Allow empty {} without line break (#261).
28-
- Wrap expr in expr before enclosing with curly braces (#263).
29-
- Avoid checking for hard-coded dot (#262).
30-
- Account for dependency renaming (utf8 changed to enc) (#264).
31-
- Indention of function declaration and closing braces (#260).
32-
- Only remove line break before closing with strict option (#252).
33-
34-
35-
## styler 0.0-9 (2017-10-23)
36-
37-
- Hotfix: utf8 should not be verbose (#245).
38-
- Allow styling of Rmd files(#233).
39-
- Remove duplicate @family (#244).
40-
- Fixing token insertion (#242).
41-
- Capitalize Addin titles (#241).
42-
- Explicit `NULL` creation to make styler compatible with R3.2.0 (#237).
43-
- Improve vignettes (#232).
44-
- Allow exclusion of files with `style_pkg()` and `style_dir()`.
45-
- Correct styling with long strings (#230).
46-
- Add tools for re-indenting tokens (#217).
47-
- Math token spacing (#221).
48-
- Remove outdated line and col information (#218).
49-
- Empty input for styling does not cause an error (#227, #228).
50-
- Tools to insert tokens + application on `if`-`else` clauses (#212).
51-
- Improve example in documentation (#222).
52-
- Fix spacing around in (#214).
53-
- Maintenance: renaming functions / files, extend helper, documentation, if_else etc. (#204).
54-
- Disallow line break after ( for function calls (#210).
55-
- Preserve space between `!` and bang (#209).
56-
- Simplify RStudio Addin (#208, #211).
57-
- Indention based on square brackets (#207).
58-
- Add vignette on introducing styler (#203).
59-
- Indent function declaration without curly braces correctly (#202).
60-
- Fix indention in if-else statement (#200).
61-
- Sorting key (#196).
62-
- Use safe sequences (#197).
63-
- Fix space between two commas (#195).
64-
- Keep single-line pipes on one line (#74).
65-
- Remove tidyr and dplyr dependency (#182, #183, @jimhester).
66-
- Fix parsing inconsistency (#188).
67-
- Substitute create filler (#190).
68-
- Introducing class vertical (#189).
69-
- Adapt line break rules (#172).
70-
- Fix `R CMD check` (#185).
71-
- Force argument evaluation for proper error handling (#179).
72-
- Add nonstrict version of set_space_before_comment (#174).
73-
- Add installation instructions to README (#175).
74-
- Addin to style highlighted region (#143).
75-
- Improve spelling (#168).
76-
- Add coverage badge
77-
- Change badge from WIP to active
78-
- Add the number of files to message (#166).
79-
- Improve documentation (#164).
80-
- Add informative messages while styling files (#165).
81-
- More examples in help file (#161).
82-
- No line breaks after pipe if comment is next token (#160).
83-
- Fixing spacing around `!` (non-bang-bang) (#157).
84-
- Finalize function documentation (#154).
85-
- Review vignette (#158).
86-
- Update bang-bang rule (#156).
87-
88-
89-
## styler 0.0-8 (2017-08-24)
90-
91-
- Vignette on customizing styler (#145).
92-
- No line break after `switch()` and friends (#152).
93-
- Remove flat relicts completely (#151).
94-
- Don't reindent function calls and break line correctly for multi-line calls (#149).
95-
- Set space between "=" and "," (#150).
96-
- Make R CMD Check perfect (#148).
97-
- Adding tests for exception handling with invalid parse data (#139).
98-
- Fix indention by checking for all potential triggers (#142).
99-
- Fix un-indention (#135).
100-
- Support wide characters (#130).
101-
- No spaces around :, :: and :::.
102-
- Redesigning the API (#123).
103-
- Solve eq_sub indention in general (#125).
104-
- Minor refactorings.
105-
- Re-indent token-dependent (#119).
106-
- Supporting more indention patterns.
107-
- Allow raw indention.
108-
- Definitively fixing eol issue with comments.
109-
- Infrastructure.
110-
- Flattening out the parse table.
111-
- New rule: no space after ! -> !!! for tidyeval.
112-
- Fix spacing around '{'.
113-
- Don't drop tokens! Fixes #101.
114-
- EOL spaces in empty comments (and in general) (#98).
115-
- mal-indention in conditional statement due to wrong specification of indent_without_paren) (#95).
116-
- Complicated indentions based on arithmetic and special operators (#96).
117-
- indention interaction on with assignment operator and other operators (#97).
118-
119-
120-
## styler 0.0-7 (2017-07-27)
121-
122-
- curly braces don't move a line up if previous token is comment.
123-
- wrap parse + transform + serialize in new function.
124-
- Speedup of nested styler functions by ~ 4x.
125-
- Use multi line instead of line1 / line2 for indention and unindention.
126-
- Indent multiple.
127-
- add tidyverse rules (indention not yet working properly).
128-
- Refactoring and add token before and afterwards to parse table.
129-
- Implement post visitor instead of complicated move_up child.
130-
131-
132-
## styler 0.0-6 (2017-07-10)
133-
134-
* Tidy up README (#43).
135-
* Fix indention of long operator chains (#69).
136-
* Properly format unary operators (#38).
137-
* Fixing indent multiple - one more time (#68).
138-
* Remove spaces before comma (#62).
139-
* Fixing indention with multiple parentheses (#57).
140-
* data.tree gains unique node IDs for proper printing.
141-
* Add `style_file()` function to style a single .R file.
142-
* Add RStudio add-in to style active .R file.
143-
* hotfix: make `style_pkg()` and `style_src()` work by passing flat argument.
144-
145-
146-
## styler 0.0-5 (2017-06-30)
147-
148-
* Correctly deal with comments (spacing before comments, start comment with space)
149-
* T more flexibly (`test_collection()` and friends now support `...`)
150-
* Indention based on curly brackets
151-
* Spacing across different levels of nesting (e.g. a space after `)` in `function(x) {...}`)
152-
* Write tree structure to file via test_collection()` for easy understanding of the nested structure
153-
* Outsource tokenise
154-
* Account for situations where code does not start on line1
155-
* Correctly style comments
156-
* Add style_empty for tailored testing
157-
* Initialize indent in create filler
158-
* Adapt vignette and documentation to visitor concept
159-
* Refine testing to use visiting approach
160-
* Parse multiple expressions: Make nested approach wok on multiple expressions too.
161-
* Internal: introducing the visitor concept instead of "looping" many times through whole nested structure.
162-
* Integrate nested approach in top-level APIs `style_text` and friends via an additional argument. `flat`.
163-
* Add tools for scalable testing. Transform *-in.R with a transformer function and check whether result corresponds to *-out.R
164-
165-
166-
## styler 0.0-4 (2017-06-15)
167-
168-
- Fix `README.Rmd` for compatibility with pkgdown.
169-
170-
171-
## styler 0.0-3 (2017-06-15)
172-
173-
- Technical release for creation of pkgdown documentation.
174-
175-
176-
## styler 0.0-2 (2017-06-15)
177-
178-
- Technical release for creation of pkgdown documentation.
179-
180-
181-
## styler 0.0-1 (2017-06-15)
182-
183-
Initial release, work in progress.
184-
185-
- Create and serialize nested parse data.
186-
- Internal support for indention of expressions with parentheses.
187-
- Adding and removing spaces around operators on flat parse data.
1+
## styler 1.0.0 (2017-12-05)
2+
3+
Initial release.
4+
5+
### stylers
6+
These are functions used to style code. They style a directory, a whole package,
7+
a file or a string.
8+
```
9+
style_dir(path = ".",
10+
..., style = tidyverse_style, transformers = style(...),
11+
filetype = "R", recursive = TRUE, exclude_files = NULL
12+
)
13+
14+
style_pkg(pkg = ".",
15+
..., style = tidyverse_style, transformers = style(...), filetype = "R",
16+
exclude_files = "R/RcppExports.R"
17+
)
18+
19+
20+
style_file(path,
21+
..., style = tidyverse_style, transformers = style(...)
22+
)
23+
24+
style_text(text, ..., style = tidyverse_style, transformers = style(...))
25+
```
26+
27+
### style guides
28+
These functions are the style guides implemented.
29+
```
30+
tidyverse_style(
31+
scope = "tokens",
32+
strict = TRUE,
33+
indent_by = 2,
34+
start_comments_with_one_space = FALSE,
35+
reindention = tidyverse_reindention(),
36+
math_token_spacing = tidyverse_math_token_spacing()
37+
)
38+
tidyverse_reindention()
39+
tidyverse_math_token_spacing())
40+
```
41+
42+
### style guide creators
43+
This function is used to create a style guide.
44+
```
45+
create_style_guide(
46+
initialize = default_style_guide_attributes,
47+
line_break = NULL,
48+
space = NULL,
49+
token = NULL,
50+
indention = NULL,
51+
use_raw_indention = FALSE,
52+
reindention = tidyverse_reindention()
53+
)
54+
```
55+
56+
### Helpers
57+
These are helper functions used to specify the style guides in use.
58+
59+
```
60+
specify_math_token_spacing(
61+
zero = NULL,
62+
one = c("'+'", "'-'", "'*'", "'/'", "'^'")
63+
)
64+
65+
specify_reindention(
66+
regex_pattern = NULL,
67+
indention = 0,
68+
comments_only = TRUE
69+
)
70+
initialize_default_attributes(pd_flat)
71+
```

R/addins.R

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ try_transform_as_r_file <- function(context, transformer) {
5050
tryCatch(
5151
transformer(context$contents),
5252
error = function(e) stop(
53-
paste(
54-
"Styling of unsaved files is only supported for R files with valid code.",
55-
"Please save the file (as .R or .Rmd) and make sure that the R code in it",
56-
"can be parsed. Then, try to style again.",
57-
"The error was \n", e
58-
), call. = FALSE
59-
))
53+
paste(
54+
"Styling of unsaved files is only supported for R files with valid code.",
55+
"Please save the file (as .R or .Rmd) and make sure that the R code in it",
56+
"can be parsed. Then, try to style again.",
57+
"The error was \n", e
58+
), call. = FALSE
59+
)
60+
)
6061
}
6162

6263
#' @describeIn styler_addins Styles the highlighted selection in a `.R` or

R/communicate.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ communicate_summary <- function(changed, ruler_width) {
2323
cli::cat_bullet("\t", sum(changed, na.rm = TRUE), "\tFile changed.", bullet = "info")
2424
cli::cat_bullet(bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an eror.")
2525
cli::cat_rule(width = max(40, ruler_width))
26-
2726
}

R/dplyr.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ arrange <- function(.data, ...) {
2424
stopifnot(is.data.frame(.data))
2525
ord <- eval(substitute(order(...)), .data, parent.frame())
2626
if (length(ord) != nrow(.data)) {
27-
stop("Length of ordering vectors don't match data frame size",
28-
call. = FALSE)
27+
stop(
28+
"Length of ordering vectors don't match data frame size",
29+
call. = FALSE
30+
)
2931
}
3032
.data[ord, , drop = FALSE]
3133
}
@@ -83,7 +85,7 @@ left_join <- function(x, y, by, ...) {
8385
res
8486
}
8587

86-
nth <- function (x, n, order_by = NULL, default = x[NA_real_]) {
88+
nth <- function(x, n, order_by = NULL, default = x[NA_real_]) {
8789
stopifnot(length(n) == 1, is.numeric(n))
8890
n <- trunc(n)
8991
if (n == 0 || n > length(x) || n < -length(x)) {
@@ -101,7 +103,7 @@ nth <- function (x, n, order_by = NULL, default = x[NA_real_]) {
101103
}
102104

103105

104-
last <- function (x, order_by = NULL, default = x[NA_real_]) {
106+
last <- function(x, order_by = NULL, default = x[NA_real_]) {
105107
nth(x, -1L, order_by = order_by, default = default)
106108
}
107109

R/expr-is.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ contains_else_expr_that_needs_braces <- function(pd) {
4747
non_comment_after_else <- next_non_comment(pd, else_idx)
4848
sub_expr <- pd$child[[non_comment_after_else]]
4949
# needs braces if NOT if_condition, NOT curly expr
50-
!is_cond_expr(sub_expr) && !is_curly_expr(sub_expr)
50+
!is_cond_expr(sub_expr) && !is_curly_expr(sub_expr)
5151
} else {
5252
FALSE
5353
}

0 commit comments

Comments
 (0)