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

Avoid spaces around ^ #308

Merged
merged 4 commits into from Feb 23, 2018
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
+66 −62
Diff settings

Always

Just for now

2 API
@@ -4,7 +4,7 @@

create_style_guide(initialize = default_style_guide_attributes, line_break = NULL, space = NULL, token = NULL, indention = NULL, use_raw_indention = FALSE, reindention = tidyverse_reindention())
default_style_guide_attributes(pd_flat)
specify_math_token_spacing(zero = NULL, one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
specify_math_token_spacing(zero = "'^'", one = c("'+'", "'-'", "'*'", "'/'"))
specify_reindention(regex_pattern = NULL, indention = 0, comments_only = TRUE)
style_dir(path = ".", ..., style = tidyverse_style, transformers = style(...), filetype = "R", recursive = TRUE, exclude_files = NULL)
style_file(path, ..., style = tidyverse_style, transformers = style(...))
@@ -27,9 +27,11 @@ set_space_around_op <- function(pd_flat) {
#' @param zero Character vector of tokens that should be surrounded with zero
#' spaces.
style_space_around_math_token <- function(strict, zero, one, pd_flat) {
# We remove spaces for zero (e.g., around ^ in the tidyverse style guide)
# even for strict = FALSE to be consistent with the : operator
pd_flat %>%
style_space_around_token(strict, zero, 0L) %>%
style_space_around_token(strict, one, 1L)
style_space_around_token(strict = TRUE, zero, 0L) %>%
style_space_around_token(strict = strict, one, 1L)
}

#' Set spacing of token to a certain level
@@ -289,20 +289,15 @@ character_to_ordered <- function(x, levels, name = substitute(x)) {
#' math_token_spacing = specify_math_token_spacing(zero = "'+'"),
#' strict = TRUE
#' )
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = TRUE
#' )
#' @name math_token_spacing
NULL

#' @describeIn math_token_spacing Allows to fully specify the math token
#' spacing.
#' @export
specify_math_token_spacing <-
function(zero = NULL,
one = c("'+'", "'-'", "'*'", "'/'", "'^'")) {
function(zero = "'^'",
one = c("'+'", "'-'", "'*'", "'/'")) {
assert_tokens(c(one, zero))
lst(
one = setdiff(c(math_token, one), zero),
@@ -317,9 +312,17 @@ specify_math_token_spacing <-
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = FALSE
#' )
#' style_text(
#' "1+1 -3",
#' math_token_spacing = tidyverse_math_token_spacing(),
#' strict = TRUE
#' )
#' @export
tidyverse_math_token_spacing <- function() {
specify_math_token_spacing(one = c("'+'", "'-'", "'*'", "'/'", "'^'"))
specify_math_token_spacing(
zero = "'^'",
one = c("'+'", "'-'", "'*'", "'/'")
)
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -17,7 +17,7 @@ a <- function(x) {
c(
list(x + 2),
c(c(
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
26 ^ 2,
8,
7
)))

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -17,7 +17,7 @@ a <- function(x) {
c(
list(x + 2),
c(c(
26 ^ 2, # FIXME ^ operator has to be surrounded by one space (or none?!), never multiple
26^2,
8,
7
))
@@ -1 +1 @@
1 + +1 - 3 / 23 * 3 ^ 4
1 + +1 - 3 / 23 * 3^4
@@ -1 +1 @@
1 + +1 - 3 / 23 * 3 ^ 4
1 + +1 - 3 / 23 * 3^4
@@ -65,7 +65,7 @@ test <- function() {
a > b
a * b
a / b
a ^ b
a^b
a & b
a | b
a := b
@@ -65,7 +65,7 @@ test <- function() {
a > b
a * b
a / b
a ^ b
a^b
a & b
a | b
a := b
@@ -42,7 +42,7 @@ if (TRUE)

if (FALSE)
1 + a * (31 / 2) else
3 ^ k
3^k


if (TRUE)
@@ -47,7 +47,7 @@ if (TRUE) {
if (FALSE) {
1 + a * (31 / 2)
} else {
3 ^ k
3^k
}


ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.