Skip to content
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

Remove unused transformers before processing #711

Merged
merged 31 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d978797
remove all edge case transformers and see speed implications
lorenzwalthert Jan 3, 2021
8cd6563
Revert "remove all edge case transformers and see speed implications"
lorenzwalthert Jan 10, 2021
82a7158
first implementation draft for touchstone
lorenzwalthert Jan 10, 2021
1fd7d80
use more elegant approach with reduce and some tests
lorenzwalthert Jan 10, 2021
6d08838
fix tests
lorenzwalthert Jan 10, 2021
d3c90bd
replace loop with walk for speed
lorenzwalthert Jan 11, 2021
48f53a3
more extensive tests for old style guides
lorenzwalthert Jan 23, 2021
4c1f95a
resolve with simple for loop
lorenzwalthert Jan 23, 2021
04c609c
fix test
lorenzwalthert Jan 23, 2021
781f796
fix R cmd check
lorenzwalthert Jan 23, 2021
9c4fc1e
make things work for R < 3.6
lorenzwalthert Jan 23, 2021
f71deae
boost by fix typo and remove indention too
lorenzwalthert Jan 23, 2021
5523a8f
another hack for old R versions
lorenzwalthert Jan 23, 2021
35976ef
if over ifelse
lorenzwalthert Jan 23, 2021
258b677
back to normal formatting
lorenzwalthert Jan 24, 2021
fd4440c
save another assignment
lorenzwalthert Jan 24, 2021
21b1f2a
remove apparently useless rule
lorenzwalthert Jan 24, 2021
4e7d97f
get rid of condition that always hold
lorenzwalthert Jan 24, 2021
1b5498e
deactivate removal for some very common operators
lorenzwalthert Jan 24, 2021
5da948b
more doc, formalize dropper
lorenzwalthert Jan 24, 2021
25cf594
doc improvement
lorenzwalthert Jan 24, 2021
7dac9eb
add news bullet
lorenzwalthert Jan 24, 2021
62ebd4b
list is so much faster than lst
lorenzwalthert Jan 24, 2021
80fee9a
put name on right side of if
lorenzwalthert Jan 24, 2021
b80a0f2
bump CI
lorenzwalthert Jan 25, 2021
c430adc
can't use if condition in assignment because it will assign NULL to t…
lorenzwalthert Jan 25, 2021
e2f3931
more thorough transformer testing
lorenzwalthert Jan 25, 2021
96ede0b
more docs
lorenzwalthert Jan 25, 2021
45dca2a
random roxygenize
lorenzwalthert Jan 23, 2021
3f3ab1c
consistently use transformers_drop
lorenzwalthert Jan 25, 2021
4e8a248
minor consistency edits
lorenzwalthert Jan 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
^API$
^README\.Rmd$
^README-.*\.png$
^.travis.yml
^appveyor\.yml$
^tic\.R$
^\.travis\.yml$
^docs$
^_pkgdown\.yml$
CONTRIBUTING.md
Expand All @@ -20,5 +18,5 @@ revdep
^\.pre-commit-config\.yaml$
^brew\-log$
^\.github/$
^touchstone/$
^.github/$
^touchstone$
^\.github$
3 changes: 2 additions & 1 deletion API
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ cache_activate(cache_name = NULL, verbose = TRUE)
cache_clear(cache_name = NULL, ask = TRUE)
cache_deactivate(verbose = TRUE)
cache_info(cache_name = NULL, format = "both")
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention(), style_guide_name = NULL, style_guide_version = NULL, more_specs_style_guide = NULL)
create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention(), style_guide_name = NULL, style_guide_version = NULL, more_specs_style_guide = NULL, transformers_drop = specify_transformers_drop())
default_style_guide_attributes(pd_flat)
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
specify_transformers_drop(spaces = NULL, indention = NULL, line_breaks = NULL, tokens = NULL)
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), recursive = TRUE, exclude_files = NULL, exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
style_file(path, ..., style = tidyverse_style, transformers = style(...), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
style_pkg(pkg = ".", ..., style = tidyverse_style, transformers = style(...), filetype = c("R", "Rprofile"), exclude_files = "R/RcppExports.R", exclude_dirs = c("packrat", "renv"), include_roxygen_examples = TRUE, base_indention = 0, dry = "off")
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(create_style_guide)
export(default_style_guide_attributes)
export(specify_math_token_spacing)
export(specify_reindention)
export(specify_transformers_drop)
export(style_dir)
export(style_file)
export(style_pkg)
Expand Down
12 changes: 9 additions & 3 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@
style tokens, you had to always also style spaces, indention, line breaks as
well (#705, #707).

- New argument `transformers_drop` in `create_style_guide()` to be populated with
new helper function `specify_transformers_drop()` for specifying conditions
under which transformers are not going to be used and can therefore be
omitted without effecting the result of styling (#711).

## Major changes


Expand All @@ -31,9 +36,10 @@
or focus loss, so this feature becomes less relevant. (#631).
- blank lines in function calls and headers are now removed, for the former only
when there are no comments before or after the blank line (#629, #630, #635).
- speed improvements: (~10%) when cache is activated because transformers are not
captured as character anymore (#679), ~ 3% in low-level optimization (#691).
Require magrittr 2.0 gives about 7% speed improvement (#681).
- speed improvements: ~10% when cache is activated because transformers are not
captured as character anymore (#679), ~3% in low-level optimization (#691).
7% by requiring magrittr 2.0 (#681), ~8% by dropping unused transformers
(#711) .
- `#<<` is now recognized as the xaringan marker and no space is added after`#`
(#700).

Expand Down
14 changes: 0 additions & 14 deletions R/rules-spaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,6 @@ set_space_in_curly_curly <- function(pd) {
pd
}

add_space_before_brace <- function(pd_flat) {
# TODO remove this, it has no effect since { can only appear in the first
# position of the nest and taking lead(op_after, default = FALSE) will always
# yield a vector of FALSE only.
op_after <- pd_flat$token %in% "'{'"
if (!any(op_after)) {
return(pd_flat)
}
op_before <- lead(op_after, default = FALSE)
idx_before <- op_before & (pd_flat$newlines == 0L) & pd_flat$token != "'('"
pd_flat$spaces[idx_before] <- pmax(pd_flat$spaces[idx_before], 1L)
pd_flat
}

add_space_after_comma <- function(pd_flat) {
comma_after <- (pd_flat$token == "','") & (pd_flat$newlines == 0L)
pd_flat$spaces[comma_after] <- pmax(pd_flat$spaces[comma_after], 1L)
Expand Down
Loading