Skip to content

Commit acd0b46

Browse files
Merge pull request #1131 from r-lib/rm-dplyr
Don't require dplyr anywhere
2 parents 68977f3 + eec8c06 commit acd0b46

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

DESCRIPTION

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ Imports:
3737
Suggests:
3838
data.tree (>= 0.1.6),
3939
digest,
40-
dplyr,
4140
here,
4241
knitr,
4342
prettycode,

tests/testthat/test-cache-low-level-api.R

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
test_that("caching utils make right blocks with semi-colon", {
22
blocks_simple_uncached <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
3-
dplyr::mutate(is_cached = FALSE) %>%
3+
base::transform(is_cached = FALSE) %>%
44
cache_find_block()
55
expect_equal(blocks_simple_uncached, c(1, 1, 1, 1))
66

77
blocks_simple_cached <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
8-
dplyr::mutate(is_cached = TRUE) %>%
8+
base::transform(is_cached = TRUE) %>%
99
cache_find_block()
1010
expect_equal(blocks_simple_cached, c(1, 1, 1, 1))
1111

1212
blocks_edge <- compute_parse_data_nested(c("1 + 1", "2; 1+1")) %>%
13-
dplyr::mutate(is_cached = c(TRUE, TRUE, FALSE, FALSE)) %>%
13+
base::transform(is_cached = c(TRUE, TRUE, FALSE, FALSE)) %>%
1414
cache_find_block()
1515
expect_equal(blocks_edge, c(1, 2, 2, 2))
1616
})
@@ -30,7 +30,7 @@ test_that("caching utils make right blocks with comments", {
3030

3131

3232
blocks_simple_uncached <- compute_parse_data_nested(text) %>%
33-
dplyr::mutate(is_cached = c(
33+
base::transform(is_cached = c(
3434
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE,
3535
TRUE, FALSE, FALSE, FALSE
3636
)) %>%
@@ -48,7 +48,7 @@ test_that("caching utils make right blocks with comments", {
4848
tau1 = 1 # here?
4949
"
5050
blocks_simple_cached <- compute_parse_data_nested(text) %>%
51-
dplyr::mutate(is_cached = c(
51+
base::transform(is_cached = c(
5252
FALSE, FALSE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE
5353
)) %>%
5454
cache_find_block()
@@ -101,17 +101,17 @@ test_that("blank lines are correctly identified", {
101101

102102
test_that("caching utils make right blocks with comments", {
103103
blocks_simple_uncached <- compute_parse_data_nested(c("1 + 1", "2 # comment")) %>%
104-
dplyr::mutate(is_cached = FALSE) %>%
104+
base::transform(is_cached = FALSE) %>%
105105
cache_find_block()
106106
expect_equal(blocks_simple_uncached, c(1, 1, 1))
107107

108108
blocks_simple_cached <- compute_parse_data_nested(c("1 + 1", "2 # comment2")) %>%
109-
dplyr::mutate(is_cached = TRUE) %>%
109+
base::transform(is_cached = TRUE) %>%
110110
cache_find_block()
111111
expect_equal(blocks_simple_cached, c(1, 1, 1))
112112

113113
blocks_edge <- compute_parse_data_nested(c("1 + 1", "2 # 1+1")) %>%
114-
dplyr::mutate(is_cached = c(TRUE, TRUE, FALSE)) %>%
114+
base::transform(is_cached = c(TRUE, TRUE, FALSE)) %>%
115115
cache_find_block()
116116
expect_equal(blocks_edge, c(1, 2, 2))
117117
})

vignettes/customizing_styler.Rmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ The `transformers` argument is, apart from the code to style, the key argument o
3232

3333
```{r, message = FALSE}
3434
library("styler")
35+
library("magrittr")
3536
cache_deactivate()
36-
library("dplyr")
3737
names(tidyverse_style())
3838
str(tidyverse_style(), give.attr = FALSE, list.len = 3)
3939
```
@@ -50,17 +50,17 @@ As the name says, this function removes spaces after the opening parenthesis. Bu
5050
string_to_format <- "call( 3)"
5151
pd <- styler:::compute_parse_data_nested(string_to_format) %>%
5252
styler:::pre_visit_one(default_style_guide_attributes)
53-
pd$child[[1]] %>%
54-
select(token, terminal, text, newlines, spaces)
53+
54+
cols <- c('token', 'terminal', 'text', 'newlines', 'spaces')
55+
pd$child[[1]][, cols]
5556
```
5657

5758
`default_style_guide_attributes()` is called to initialize some variables, it does not actually transform the parse table.
5859

5960
All the function `remove_space_after_opening_paren()` now does is to look for the opening bracket and set the column `spaces` of the token to zero. Note that it is very important to check whether there is also a line break following after that token. If so, `spaces` should not be touched because of the way `spaces` and `newlines` are defined. `spaces` are the number of spaces after a token and `newlines`. Hence, if a line break follows, spaces are not EOL spaces, but rather the spaces directly before the next token. If there was a line break after the token and the rule did not check for that, indention for the token following `(` would be removed. This would be unwanted for example if `use_raw_indention` is set to `TRUE` (which means indention should not be touched). If we apply the rule to our parse table, we can see that the column `spaces` changes and is now zero for all tokens:
6061

6162
```{r}
62-
styler:::remove_space_after_opening_paren(pd$child[[1]]) %>%
63-
select(token, terminal, text, newlines, spaces)
63+
styler:::remove_space_after_opening_paren(pd$child[[1]])[, cols]
6464
```
6565

6666
All top-level styling functions have a `style` argument (which defaults to `tidyverse_style`). If you check out the help file, you can see that the argument `style` is only used to create the default `transformers` argument, which defaults to `style(...)`. This allows for the styling options to be set without having to specify them inside the function passed to `transformers`.

0 commit comments

Comments
 (0)