Skip to content

Commit 1d71bc2

Browse files
Merge pull request #316 from lorenzwalthert/tilde
- Spaces around tilde (#316).
2 parents d4abea3 + 1341f5c commit 1d71bc2

File tree

10 files changed

+62
-35
lines changed

10 files changed

+62
-35
lines changed

R/rules-spacing.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ set_space_around_op <- function(pd_flat) {
2020
}
2121

2222
#' Style spacing around math tokens
23-
#' @inheritParams style_space_around_math_token_one
23+
#' @inheritParams style_space_around_token
2424
#' @param one Character vector with tokens that should be surrounded by at
2525
#' least one space (depending on `strict = TRUE` in the styling functions
2626
#' [style_text()] and friends). See 'Examples'.
2727
#' @param zero Character vector of tokens that should be surrounded with zero
2828
#' spaces.
2929
style_space_around_math_token <- function(strict, zero, one, pd_flat) {
3030
pd_flat %>%
31-
style_space_around_math_token_one(strict, zero, 0L) %>%
32-
style_space_around_math_token_one(strict, one, 1L)
31+
style_space_around_token(strict, zero, 0L) %>%
32+
style_space_around_token(strict, one, 1L)
3333
}
3434

3535
#' Set spacing of token to a certain level
@@ -41,7 +41,7 @@ style_space_around_math_token <- function(strict, zero, one, pd_flat) {
4141
#' @param tokens Character vector with tokens that should be styled.
4242
#' @param level Scalar indicating the amount of spaces that should be inserted
4343
#' around the `tokens`.
44-
style_space_around_math_token_one <- function(pd_flat, strict, tokens, level) {
44+
style_space_around_token <- function(pd_flat, strict, tokens, level) {
4545
op_after <- pd_flat$token %in% tokens
4646
op_before <- lead(op_after, default = FALSE)
4747
idx_before <- op_before & (pd_flat$newlines == 0L)

R/style_guides.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ tidyverse_style <- function(scope = "tokens",
8080
math_token_spacing$zero,
8181
math_token_spacing$one
8282
),
83+
partial(
84+
style_space_around_token, strict = strict, tokens = "'~'", level = 1),
8385
if (strict) set_space_around_op else add_space_around_op,
8486
if (strict) set_space_after_comma else add_space_after_comma,
8587
remove_space_after_opening_paren,

R/token-define.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ token <- tribble(
1919
"*" , "math" , "'*'" ,
2020
"/" , "math" , "'/'" ,
2121
"^" , "math" , "'^'" ,
22+
"~" , "formula" , "'~'" ,
2223
"if" , "cond" , "IF" ,
2324
"else" , "cond" , "ELSE" ,
2425
"in" , "loop_cond" , "IN" ,

man/style_space_around_math_token_one.Rd renamed to man/style_space_around_token.Rd

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/strict/non_strict-in.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,3 +140,4 @@ lm(a~b+c,data=NA)
140140
lm(a~.-1,data=NA)
141141
a~b:c
142142
a~b :c
143+
a ~ b : c

tests/testthat/strict/non_strict-in_tree

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/strict/non_strict-out.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ test <- function() {
135135

136136

137137
# formula
138-
lm(a~b + c, data = NA)
139-
lm(a~. - 1, data = NA)
140-
a~b:c
141-
a~b:c
138+
lm(a ~ b + c, data = NA)
139+
lm(a ~ . - 1, data = NA)
140+
a ~ b:c
141+
a ~ b:c
142+
a ~ b:c

tests/testthat/strict/strict-in.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,5 @@ test <- function() {
139139
lm(a~b+c,data=NA)
140140
lm(a~.-1,data=NA)
141141
a~b:c
142+
a ~ b : c
142143
a~b :c

tests/testthat/strict/strict-in_tree

Lines changed: 20 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/strict/strict-out.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ test <- function() {
140140

141141

142142
# formula
143-
lm(a~b + c, data = NA)
144-
lm(a~. - 1, data = NA)
145-
a~b:c
146-
a~b:c
143+
lm(a ~ b + c, data = NA)
144+
lm(a ~ . - 1, data = NA)
145+
a ~ b:c
146+
a ~ b:c
147+
a ~ b:c

0 commit comments

Comments
 (0)