Skip to content

Commit f49050b

Browse files
committed
Merge branch 'r-0.0-11' into production
2 parents a92eb07 + 924ad91 commit f49050b

File tree

84 files changed

+911
-238
lines changed

Some content is hidden

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

84 files changed

+911
-238
lines changed

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
^docs$
1111
^_pkgdown\.yml$
1212
CONTRIBUTING.md
13+
^\.gitsum$
14+
^gitsum$
15+

API

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
## Exported functions
44

55
create_style_guide(initialize = initialize_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
6-
regex_none()
76
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
8-
specify_reindention(regex_pattern = regex_none(), indention = 0, comments_only = TRUE)
9-
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), recursive = TRUE, exclude_files = NULL)
7+
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
8+
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL)
109
style_file(path, ..., style = tidyverse_style, transformers = style(...))
11-
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), exclude_files = "R/RcppExports.R")
10+
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", exclude_files = "R/RcppExports.R")
1211
style_text(text, ..., style = tidyverse_style, transformers = style(...))
1312
tidyverse_math_token_spacing()
1413
tidyverse_reindention()
1514
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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
Package: styler
22
Title: Non-invasive Pretty Printing of R code
3-
Version: 0.0-10
3+
Version: 0.0-11
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:
77
Pretty-prints R code without changing the user's formatting intent.
88
Imports:
99
backports,
10+
cli,
1011
enc,
1112
magrittr,
1213
purrr,
@@ -27,14 +28,15 @@ Suggests:
2728
License: GPL-3
2829
Encoding: UTF-8
2930
LazyData: true
30-
Date: 2017-11-27
31+
Date: 2017-12-05
3132
BugReports: https://github.com/r-lib/styler/issues
3233
URL: https://github.com/r-lib/styler, https://r-lib.github.io/styler/
3334
Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate", "pkgapi::api_roclet"))
3435
RoxygenNote: 6.0.1
3536
VignetteBuilder: knitr
3637
Collate:
3738
'addins.R'
39+
'communicate.R'
3840
'compat-tidyr.R'
3941
'dplyr.R'
4042
'expr-is.R'
@@ -52,6 +54,7 @@ Collate:
5254
'rules-spacing.R'
5355
'serialize.R'
5456
'serialized_tests.R'
57+
'set-assert-args.R'
5558
'style_guides.R'
5659
'styler.R'
5760
'token-create.R'

NAMESPACE

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

33
S3method(print,vertical)
44
export(create_style_guide)
5-
export(regex_none)
65
export(specify_math_token_spacing)
76
export(specify_reindention)
87
export(style_dir)

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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+
111
## styler 0.0-10 (2017-11-27)
212

313
- Adapt documentation (#290).

R/addins.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ try_transform_as_r_file <- function(context, transformer) {
5050
tryCatch(
5151
transformer(context$contents),
5252
error = function(e) stop(
53-
"Cannot style unsaved files other than .R files. Please save the file.", call. = FALSE
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
5459
))
5560
}
5661

R/communicate.R

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#' Communicate a warning if necessary
2+
#'
3+
#' If roundtrip verification was not possible, issue a warning to review the
4+
#' changes carefully.
5+
#' @param changed Boolean with indicating for each file whether or not it has
6+
#' been changed.
7+
#' @inheritParams can_verify_roundtrip
8+
communicate_warning <- function(changed, transformers) {
9+
if (any(changed, na.rm = TRUE) && !can_verify_roundtrip(transformers)) {
10+
cat("Please review the changes carefully!")
11+
}
12+
}
13+
14+
#' Communicate the summary of styling
15+
#'
16+
#' @param changed Boolean with indicating for each file whether or not it has
17+
#' been changed.
18+
#' @param ruler_width Integer used to determine the width of the ruler.
19+
communicate_summary <- function(changed, ruler_width) {
20+
cli::cat_rule(width = max(40, ruler_width))
21+
cat("Status\tCount\tLegend \n")
22+
cli::cat_bullet("\t", sum(!changed, na.rm = TRUE), "\tFile unchanged.", bullet = "tick")
23+
cli::cat_bullet("\t", sum(changed, na.rm = TRUE), "\tFile changed.", bullet = "info")
24+
cli::cat_bullet(bullet = "cross", "\t", sum(is.na(changed)), "\tStyling threw an eror.")
25+
cli::cat_rule(width = max(40, ruler_width))
26+
27+
}

R/expr-is.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' Check whether a parse table corresponds to a a certain expression
1+
#' Check whether a parse table corresponds to a certain expression
22
#'
33
#' @param pd A parse table.
44
#' @name pd_is
@@ -39,7 +39,7 @@ contains_else_expr <- function(pd) {
3939
#' Checks whether an else expression in a nest needs braces. Note that for
4040
#' if-else-if expressions, there is no need to add braces since the if in
4141
#' else-if will be visited separately with the visitor. This applies to all
42-
#' conditional statents with more than one alternative.
42+
#' conditional statements with more than one alternative.
4343
#' @param pd A parse table
4444
contains_else_expr_that_needs_braces <- function(pd) {
4545
else_idx <- which(pd$token == "ELSE")

R/indent.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ pd_is_multi_line <- function(pd) {
194194

195195
#' Update the newlines attribute
196196
#'
197-
#' As we work only with the `lag_newlines` attribute for setting the linebreaks,
198-
#' (R/rules-line_break.R) but we need `newlines` to determine
197+
#' As we work only with the `lag_newlines` attribute for setting the line
198+
#' breaks, (R/rules-line_break.R) but we need `newlines` to determine
199199
#' whether or not to set `spaces` (R/rules-spacing.R), we have to update the
200200
#' attribute. We cannot simply use `dplyr::lead(pd$lag_newlines)` since we would
201201
#' lose information for the last token. `spaces` is left as is in

R/parse.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) {
3737

3838
#' Add column `pos_id` and `short`
3939
#'
40-
#' Addds column `pos_id` and `short` to a flat parse table.
40+
#' Adds column `pos_id` and `short` to a flat parse table.
4141
#' @param pd A flat parse table
4242
add_id_and_short <- function(pd) {
4343
pd$pos_id <- seq2(1L, nrow(pd))

0 commit comments

Comments
 (0)