From 46b8f0c58dad5d6855d0ecd0ab11096920c8ce42 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 23 Aug 2022 09:19:28 +0200 Subject: [PATCH 01/12] Also test with parser version 1 --- .github/workflows/check-full.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index 36884035c..e9cf272f2 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -33,6 +33,7 @@ jobs: - {os: ubuntu-latest, r: 'oldrel-2'} - {os: ubuntu-latest, r: 'oldrel-3'} - {os: ubuntu-latest, r: 'oldrel-4'} + - {os: ubuntu-latest, r: '3.4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} From b87f626107cdf740a0a87ae9f31e55c5e107f579 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 23 Aug 2022 10:22:16 +0200 Subject: [PATCH 02/12] Bump minimum needed R version --- .github/workflows/check-full.yaml | 1 - DESCRIPTION | 2 +- NEWS.md | 3 ++- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index e9cf272f2..36884035c 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -33,7 +33,6 @@ jobs: - {os: ubuntu-latest, r: 'oldrel-2'} - {os: ubuntu-latest, r: 'oldrel-3'} - {os: ubuntu-latest, r: 'oldrel-4'} - - {os: ubuntu-latest, r: '3.4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/DESCRIPTION b/DESCRIPTION index b9c69e888..1ba5c849b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE URL: https://github.com/r-lib/styler, https://styler.r-lib.org BugReports: https://github.com/r-lib/styler/issues Depends: - R (>= 3.4.0) + R (>= 3.5.0) Imports: cli (>= 3.1.1), magrittr (>= 2.0.0), diff --git a/NEWS.md b/NEWS.md index 086c9eaba..a81e78e60 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,7 +11,8 @@ editor_options: - `style_dir()` and `style_pkg()` now default to styling all supported file formats (`.R`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.qmd`) in the (package) directory (\@IndrajeetPatil, #965). -- `style_pkg()` now excludes the auto-generated `R/cpp11.R` file (#977). +- `style_pkg()` now excludes the auto-generated `R/cpp11.R` file (#977). +- Minimum needed R version is now bumped to `3.5` (\@IndrajeetPatil, #985). **Features** From bd564c7393ec1d90195f938aa39a989e04231786 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 23 Aug 2022 10:36:42 +0200 Subject: [PATCH 03/12] Get rid of logic related to parser version 1 --- R/relevel.R | 119 ++-------------------------- man/add_line_col_to_wrapped_expr.Rd | 15 ---- man/find_block_id.Rd | 21 ----- man/relocate_eq_assign.Rd | 17 +--- man/relocate_eq_assign_nest.Rd | 33 -------- man/relocate_eq_assign_one.Rd | 17 ---- 6 files changed, 10 insertions(+), 212 deletions(-) delete mode 100644 man/add_line_col_to_wrapped_expr.Rd delete mode 100644 man/find_block_id.Rd delete mode 100644 man/relocate_eq_assign_nest.Rd delete mode 100644 man/relocate_eq_assign_one.Rd diff --git a/R/relevel.R b/R/relevel.R index c8984a5d1..878f49b5d 100644 --- a/R/relevel.R +++ b/R/relevel.R @@ -27,7 +27,7 @@ flatten_operators_one <- function(pd_nested) { pd_token_left <- c(special_token, "PIPE", math_token, "'$'") pd_token_right <- c( special_token, "PIPE", "LEFT_ASSIGN", - if (parser_version_get() > 1) "EQ_ASSIGN", + "EQ_ASSIGN", "'+'", "'-'", "'~'" ) pd_nested %>% @@ -111,19 +111,11 @@ wrap_expr_in_expr <- function(pd) { #' Relocate the expressions containing the token `EQ_ASSIGN` within the nested #' parse table #' -#' Although syntactically identical, [utils::getParseData()] does not produce -#' the same hierarchy of the parse table (parent and id relationship) for `<-` -#' and `=` (See 'Examples'). -#' This is considered to be a bug and causes problems because the -#' nested parse table constructed with [compute_parse_data_nested()] is not -#' consistent if `EQ_ASSIGN` occurs in the expression to style. In particular, -#' `EQ_ASSIGN` and the tokens to its left and right are located too high up in -#' the hierarchy of the nested parse data. Hence, this function wraps the -#' sub-expression into an expression, similar to [wrap_expr_in_curly()]. -#' Since `wrap_expr_in_curly()` is called from within a visitor -#' (and `relocate_eq_assign()` not), we need to -#' wrap the the implementation [relocate_eq_assign_nest()] that operates on -#' *nests* into a visitor call. +#' This used to be relevant when `{styler}` supported R versions `< 3.5`, and, +#' therefore, parser version `1`, which had a bug that did not produce the same +#' hierarchy of the parse table (parent and id relationship) for `<-` and `=` +#' (See 'Examples'). +#' #' @param pd A parse table. #' @examples #' styler:::get_parse_data("a <- b <- 3") @@ -142,104 +134,5 @@ wrap_expr_in_expr <- function(pd) { #' ) #' @keywords internal relocate_eq_assign <- function(pd) { - if (parser_version_get() < 2) { - post_visit_one(pd, relocate_eq_assign_nest) - } else { - pd - } -} - - -#' Relocate all assignment expressions that contain `EQ_ASSIGN` within a *nest* -#' -#' Implements the relocation of an `EQ_ASSIGN` and associated tokens -#' within a *nest* (nested parse table at one level of nesting). -#' Note that one assignment expression (such as "a = b = c") can include -#' multiple assignment operators, an assignment involves just one assignment -#' operator. -#' For the relocation of assignment expressions that contain `EQ_ASSIGN` within -#' a *nest*, we need to first find the expressions that contain `=` and then -#' split the *nest* into parse tables each containing one such assignment -#' expression and then relocate each of them separately. -#' We can't do all of them together because: -#' -#' * An assignment can contain more than just three tokens, e.g. (a <- b <- c). -#' * Two assignments can be in the same nest although they don't belong to the -#' same assignment (if-else statement). -#' -#' Please refer to the section 'Examples' in [relocate_eq_assign()] for details. -#' @param pd A parse table. -#' @importFrom rlang seq2 -#' @keywords internal -relocate_eq_assign_nest <- function(pd) { - idx_eq_assign <- which(pd$token == "EQ_ASSIGN") - if (length(idx_eq_assign) > 0) { - block_id <- find_block_id(pd) - blocks <- split(pd, block_id) - pd <- map_dfr(blocks, relocate_eq_assign_one) - } - pd -} - -#' Find the block to which a token belongs -#' -#' Two assignment tokens `EQ_ASSIGN` belong to the same block if they are not -#' separated by more than one token. Token between `EQ_ASSIGN` tokens belong -#' to the `EQ_ASSIGN` token occurring before them, except the token right before -#' `EQ_ASSING` already belongs to the `EQ_ASSING` after it. Note that this -#' notion is unrelated to the column *block* in the parse table, which is used -#' to [parse_transform_serialize_r()] code blocks and leave out the ones that -#' are cached. -#' @param pd A parse table. -#' @keywords internal -find_block_id <- function(pd) { - idx_eq_assign <- which(pd$token == "EQ_ASSIGN") - eq_belongs_to_block <- c(0, diff(idx_eq_assign) > 2) - - empty_seq <- rep(0, nrow(pd)) - empty_seq[idx_eq_assign - 1] <- eq_belongs_to_block - block_id <- cumsum(empty_seq) - block_id -} - -#' Relocate an assignment expression -#' -#' Relocates an assignment expression within a parse table containing one -#' assignment expression. Note that one assignment can include multiple -#' assignment operators such as "a = b = c". -#' @param pd A parse table with one assignment expression to relocate. -#' @keywords internal -relocate_eq_assign_one <- function(pd) { - idx_eq_assign <- which(pd$token == "EQ_ASSIGN") - eq_ind <- seq2(idx_eq_assign[1] - 1L, last(idx_eq_assign) + 1L) - # initialize because wrap_expr_in_expr -> create_tokens -> requires it - pd$indent <- 0 - eq_expr <- pd[eq_ind, ] %>% - wrap_expr_in_expr() %>% - add_line_col_to_wrapped_expr() %>% - remove_attributes(c( - "multi_line", "indention_ref_pos_id", - "newlines", "indent", "spaces", "lag_newlines" - )) - eq_expr$id <- NA - eq_expr$parent <- NA - pd$indent <- NULL - non_eq_expr <- pd[-eq_ind, ] - pd <- bind_rows(eq_expr, non_eq_expr) %>% - arrange_pos_id() - pd -} - -#' Adds line and col information to an expression from its child -#' -#' @param pd A parse table. -#' @importFrom rlang abort -#' @keywords internal -add_line_col_to_wrapped_expr <- function(pd) { - if (nrow(pd) > 1) abort("pd must be a wrapped expression that has one row.") - pd$line1 <- pd$child[[1]]$line1[1] - pd$line2 <- last(pd$child[[1]]$line2) - pd$col1 <- pd$child[[1]]$col1[1] - pd$col2 <- last(pd$child[[1]]$col2) pd } diff --git a/man/add_line_col_to_wrapped_expr.Rd b/man/add_line_col_to_wrapped_expr.Rd deleted file mode 100644 index dc7b0d333..000000000 --- a/man/add_line_col_to_wrapped_expr.Rd +++ /dev/null @@ -1,15 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/relevel.R -\name{add_line_col_to_wrapped_expr} -\alias{add_line_col_to_wrapped_expr} -\title{Adds line and col information to an expression from its child} -\usage{ -add_line_col_to_wrapped_expr(pd) -} -\arguments{ -\item{pd}{A parse table.} -} -\description{ -Adds line and col information to an expression from its child -} -\keyword{internal} diff --git a/man/find_block_id.Rd b/man/find_block_id.Rd deleted file mode 100644 index 2635a8420..000000000 --- a/man/find_block_id.Rd +++ /dev/null @@ -1,21 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/relevel.R -\name{find_block_id} -\alias{find_block_id} -\title{Find the block to which a token belongs} -\usage{ -find_block_id(pd) -} -\arguments{ -\item{pd}{A parse table.} -} -\description{ -Two assignment tokens \code{EQ_ASSIGN} belong to the same block if they are not -separated by more than one token. Token between \code{EQ_ASSIGN} tokens belong -to the \code{EQ_ASSIGN} token occurring before them, except the token right before -\code{EQ_ASSING} already belongs to the \code{EQ_ASSING} after it. Note that this -notion is unrelated to the column \emph{block} in the parse table, which is used -to \code{\link[=parse_transform_serialize_r]{parse_transform_serialize_r()}} code blocks and leave out the ones that -are cached. -} -\keyword{internal} diff --git a/man/relocate_eq_assign.Rd b/man/relocate_eq_assign.Rd index 5faf42e35..7094b428a 100644 --- a/man/relocate_eq_assign.Rd +++ b/man/relocate_eq_assign.Rd @@ -11,19 +11,10 @@ relocate_eq_assign(pd) \item{pd}{A parse table.} } \description{ -Although syntactically identical, \code{\link[utils:getParseData]{utils::getParseData()}} does not produce -the same hierarchy of the parse table (parent and id relationship) for \verb{<-} -and \code{=} (See 'Examples'). -This is considered to be a bug and causes problems because the -nested parse table constructed with \code{\link[=compute_parse_data_nested]{compute_parse_data_nested()}} is not -consistent if \code{EQ_ASSIGN} occurs in the expression to style. In particular, -\code{EQ_ASSIGN} and the tokens to its left and right are located too high up in -the hierarchy of the nested parse data. Hence, this function wraps the -sub-expression into an expression, similar to \code{\link[=wrap_expr_in_curly]{wrap_expr_in_curly()}}. -Since \code{wrap_expr_in_curly()} is called from within a visitor -(and \code{relocate_eq_assign()} not), we need to -wrap the the implementation \code{\link[=relocate_eq_assign_nest]{relocate_eq_assign_nest()}} that operates on -\emph{nests} into a visitor call. +This used to be relevant when \code{{styler}} supported R versions \verb{< 3.5}, and, +therefore, parser version \code{1}, which had a bug that did not produce the same +hierarchy of the parse table (parent and id relationship) for \verb{<-} and \code{=} +(See 'Examples'). } \examples{ styler:::get_parse_data("a <- b <- 3") diff --git a/man/relocate_eq_assign_nest.Rd b/man/relocate_eq_assign_nest.Rd deleted file mode 100644 index e66177d45..000000000 --- a/man/relocate_eq_assign_nest.Rd +++ /dev/null @@ -1,33 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/relevel.R -\name{relocate_eq_assign_nest} -\alias{relocate_eq_assign_nest} -\title{Relocate all assignment expressions that contain \code{EQ_ASSIGN} within a \emph{nest}} -\usage{ -relocate_eq_assign_nest(pd) -} -\arguments{ -\item{pd}{A parse table.} -} -\description{ -Implements the relocation of an \code{EQ_ASSIGN} and associated tokens -within a \emph{nest} (nested parse table at one level of nesting). -Note that one assignment expression (such as "a = b = c") can include -multiple assignment operators, an assignment involves just one assignment -operator. -For the relocation of assignment expressions that contain \code{EQ_ASSIGN} within -a \emph{nest}, we need to first find the expressions that contain \code{=} and then -split the \emph{nest} into parse tables each containing one such assignment -expression and then relocate each of them separately. -We can't do all of them together because: -} -\details{ -\itemize{ -\item An assignment can contain more than just three tokens, e.g. (a <- b <- c). -\item Two assignments can be in the same nest although they don't belong to the -same assignment (if-else statement). -} - -Please refer to the section 'Examples' in \code{\link[=relocate_eq_assign]{relocate_eq_assign()}} for details. -} -\keyword{internal} diff --git a/man/relocate_eq_assign_one.Rd b/man/relocate_eq_assign_one.Rd deleted file mode 100644 index 90318565e..000000000 --- a/man/relocate_eq_assign_one.Rd +++ /dev/null @@ -1,17 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/relevel.R -\name{relocate_eq_assign_one} -\alias{relocate_eq_assign_one} -\title{Relocate an assignment expression} -\usage{ -relocate_eq_assign_one(pd) -} -\arguments{ -\item{pd}{A parse table with one assignment expression to relocate.} -} -\description{ -Relocates an assignment expression within a parse table containing one -assignment expression. Note that one assignment can include multiple -assignment operators such as "a = b = c". -} -\keyword{internal} From f75a5652b6d5214f7907441458c9ba5450a2eeab Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 23 Aug 2022 11:05:07 +0200 Subject: [PATCH 04/12] Don't update NEWS for now --- DESCRIPTION | 2 +- NEWS.md | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 1ba5c849b..2a53fb0ee 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -18,7 +18,7 @@ License: MIT + file LICENSE URL: https://github.com/r-lib/styler, https://styler.r-lib.org BugReports: https://github.com/r-lib/styler/issues Depends: - R (>= 3.5.0) + R (>= 3.6.0) Imports: cli (>= 3.1.1), magrittr (>= 2.0.0), diff --git a/NEWS.md b/NEWS.md index a81e78e60..813a43485 100644 --- a/NEWS.md +++ b/NEWS.md @@ -12,7 +12,6 @@ editor_options: formats (`.R`, `.Rmd`, `.Rmarkdown`, `.Rnw`, and `.qmd`) in the (package) directory (\@IndrajeetPatil, #965). - `style_pkg()` now excludes the auto-generated `R/cpp11.R` file (#977). -- Minimum needed R version is now bumped to `3.5` (\@IndrajeetPatil, #985). **Features** From f3c9c090311b3b6bb61010ea015b1893950a3f42 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Tue, 23 Aug 2022 12:08:38 +0200 Subject: [PATCH 05/12] get rid of more logic for R < 3.6 --- R/style-guides.R | 4 ---- tests/testthat/test-transformers-drop.R | 5 +---- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/R/style-guides.R b/R/style-guides.R index 4de3211f1..1be192439 100644 --- a/R/style-guides.R +++ b/R/style-guides.R @@ -238,10 +238,6 @@ tidyverse_style <- function(scope = "tokens", ) ) - if (getRversion() < "3.6") { - transformers_drop$token$force_assignment_op <- NULL - } - style_guide_name <- "styler::tidyverse_style@https://github.com/r-lib" create_style_guide( # transformer functions diff --git a/tests/testthat/test-transformers-drop.R b/tests/testthat/test-transformers-drop.R index 18ce38eaf..0410e19bf 100644 --- a/tests/testthat/test-transformers-drop.R +++ b/tests/testthat/test-transformers-drop.R @@ -94,10 +94,7 @@ test_that("tidyverse transformers are correctly dropped", { names_indention <- c("indent_braces", "indent_op", "indent_without_paren") expect_setequal(names(t_fun$indention), names_indention) - names_tokens <- c( - "fix_quotes", - if (getRversion() < "3.6") "force_assignment_op" - ) + names_tokens <- "fix_quotes" expect_setequal(names(t_fun$token), names_tokens) }) From 900b7808e788f9c4e79bdc39b0877d2847d3d627 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 9 Sep 2022 14:30:43 +0200 Subject: [PATCH 06/12] some more R 3.6 clean up --- R/environments.R | 8 +------- R/parse.R | 2 +- R/relevel.R | 6 +----- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/R/environments.R b/R/environments.R index b5ce9e80a..7d248c4b4 100755 --- a/R/environments.R +++ b/R/environments.R @@ -43,13 +43,7 @@ parser_version_get <- function() { #' @rdname parser_version_set parser_version_find <- function(pd) { - ifelse(any(pd$token == "equal_assign"), - 2, - ifelse(any(pd$token == "expr_or_assign_or_help"), - 3, - 1 - ) - ) + ifelse(any(pd$token == "equal_assign"), 2, 3) } diff --git a/R/parse.R b/R/parse.R index 3651ce2a7..2dd9376e9 100644 --- a/R/parse.R +++ b/R/parse.R @@ -111,7 +111,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) { pd <- pd %>% add_id_and_short() - parser_version_set(parser_version_find(pd)) + #parser_version_set(parser_version_find(pd)) pd } diff --git a/R/relevel.R b/R/relevel.R index 878f49b5d..495770d32 100644 --- a/R/relevel.R +++ b/R/relevel.R @@ -25,11 +25,7 @@ flatten_operators <- function(pd_nested) { #' @keywords internal flatten_operators_one <- function(pd_nested) { pd_token_left <- c(special_token, "PIPE", math_token, "'$'") - pd_token_right <- c( - special_token, "PIPE", "LEFT_ASSIGN", - "EQ_ASSIGN", - "'+'", "'-'", "'~'" - ) + pd_token_right <- c(special_token, "PIPE", "LEFT_ASSIGN", "EQ_ASSIGN", "'+'", "'-'", "'~'") pd_nested %>% flatten_pd(pd_token_left, left = TRUE) %>% flatten_pd(pd_token_right, left = FALSE) From 95251902a0cdbd0a7fd039b9b061db90db45c76d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 9 Sep 2022 12:35:49 +0000 Subject: [PATCH 07/12] pre-commit --- R/parse.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/parse.R b/R/parse.R index 2dd9376e9..298d1f271 100644 --- a/R/parse.R +++ b/R/parse.R @@ -111,7 +111,7 @@ get_parse_data <- function(text, include_text = TRUE, ...) { pd <- pd %>% add_id_and_short() - #parser_version_set(parser_version_find(pd)) + # parser_version_set(parser_version_find(pd)) pd } From 3739ddf5b00296ade788c0db0f2596a262e2e064 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 9 Sep 2022 14:39:24 +0200 Subject: [PATCH 08/12] turn off oldrel-4 for now --- .github/workflows/check-full.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-full.yaml b/.github/workflows/check-full.yaml index dc4fb8f58..6551d2fc7 100644 --- a/.github/workflows/check-full.yaml +++ b/.github/workflows/check-full.yaml @@ -32,7 +32,7 @@ jobs: - {os: ubuntu-latest, r: 'oldrel-1'} - {os: ubuntu-latest, r: 'oldrel-2'} - {os: ubuntu-latest, r: 'oldrel-3'} - - {os: ubuntu-latest, r: 'oldrel-4'} + #- {os: ubuntu-latest, r: 'oldrel-4'} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} From 5a12099bb690a9947be2430bc61225db381d49a8 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Fri, 9 Sep 2022 15:22:42 +0200 Subject: [PATCH 09/12] `relocate_eq_assign()` is no longer needed --- R/nest.R | 1 - R/relevel.R | 33 --------------------------------- man/relocate_eq_assign.Rd | 35 ----------------------------------- 3 files changed, 69 deletions(-) delete mode 100644 man/relocate_eq_assign.Rd diff --git a/R/nest.R b/R/nest.R index 09704bc9c..9144f7fce 100644 --- a/R/nest.R +++ b/R/nest.R @@ -16,7 +16,6 @@ compute_parse_data_nested <- function(text, pd_nested <- parse_data %>% nest_parse_data() %>% flatten_operators() %>% - when(any(parse_data$token == "EQ_ASSIGN") ~ relocate_eq_assign(.), ~.) %>% add_cache_block() pd_nested diff --git a/R/relevel.R b/R/relevel.R index 495770d32..11d31e14a 100644 --- a/R/relevel.R +++ b/R/relevel.R @@ -99,36 +99,3 @@ wrap_expr_in_expr <- function(pd) { indents = pd$indent[1] ) } - - -# ____________________________________________________________________________ -# Relocate EQ_ASSIGN #### - -#' Relocate the expressions containing the token `EQ_ASSIGN` within the nested -#' parse table -#' -#' This used to be relevant when `{styler}` supported R versions `< 3.5`, and, -#' therefore, parser version `1`, which had a bug that did not produce the same -#' hierarchy of the parse table (parent and id relationship) for `<-` and `=` -#' (See 'Examples'). -#' -#' @param pd A parse table. -#' @examples -#' styler:::get_parse_data("a <- b <- 3") -#' styler:::get_parse_data("a = b = 3") -#' styler:::get_parse_data( -#' "x = 5 -#' if(x >= 5) -#' y = TRUE else -#' y = FALSE", -#' ) -#' styler:::get_parse_data( -#' "x <- 5 -#' if(x >= 5) -#' y <- TRUE else -#' y <- FALSE", -#' ) -#' @keywords internal -relocate_eq_assign <- function(pd) { - pd -} diff --git a/man/relocate_eq_assign.Rd b/man/relocate_eq_assign.Rd deleted file mode 100644 index 7094b428a..000000000 --- a/man/relocate_eq_assign.Rd +++ /dev/null @@ -1,35 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/relevel.R -\name{relocate_eq_assign} -\alias{relocate_eq_assign} -\title{Relocate the expressions containing the token \code{EQ_ASSIGN} within the nested -parse table} -\usage{ -relocate_eq_assign(pd) -} -\arguments{ -\item{pd}{A parse table.} -} -\description{ -This used to be relevant when \code{{styler}} supported R versions \verb{< 3.5}, and, -therefore, parser version \code{1}, which had a bug that did not produce the same -hierarchy of the parse table (parent and id relationship) for \verb{<-} and \code{=} -(See 'Examples'). -} -\examples{ -styler:::get_parse_data("a <- b <- 3") -styler:::get_parse_data("a = b = 3") -styler:::get_parse_data( - "x = 5 - if(x >= 5) - y = TRUE else - y = FALSE", -) -styler:::get_parse_data( - "x <- 5 - if(x >= 5) - y <- TRUE else - y <- FALSE", -) -} -\keyword{internal} From 5fc30da4edc52f18f37edf5aa36e55bbc50b5d4f Mon Sep 17 00:00:00 2001 From: Lorenz Walthert Date: Sun, 11 Sep 2022 15:39:36 +0200 Subject: [PATCH 10/12] always define global variables --- R/styler.R | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/R/styler.R b/R/styler.R index a6e44e870..4409a837b 100644 --- a/R/styler.R +++ b/R/styler.R @@ -18,15 +18,13 @@ #' style_text("a%>%b; a", scope = "tokens") "_PACKAGE" -if (getRversion() >= "2.15.1") { - utils::globalVariables(c( - ".", - "pd", "pd_nested", "pd_flat", "flattened_pd", - "line1", "line2", "col1", "col2", "parent", - "terminal", "text", "short", - "spaces", "lag_spaces", - "newlines", "lag_newlines", - "pos_id", - NULL - )) -} +utils::globalVariables(c( + ".", + "pd", "pd_nested", "pd_flat", "flattened_pd", + "line1", "line2", "col1", "col2", "parent", + "terminal", "text", "short", + "spaces", "lag_spaces", + "newlines", "lag_newlines", + "pos_id", + NULL +)) From 475c836009931db5d4bd4fe4ced2562d375a844b Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Sun, 11 Sep 2022 15:47:32 +0200 Subject: [PATCH 11/12] remove its usage, but retain the logic for future --- R/parse.R | 1 - R/utils-navigate-nest.R | 1 - 2 files changed, 2 deletions(-) diff --git a/R/parse.R b/R/parse.R index 298d1f271..909657c89 100644 --- a/R/parse.R +++ b/R/parse.R @@ -111,7 +111,6 @@ get_parse_data <- function(text, include_text = TRUE, ...) { pd <- pd %>% add_id_and_short() - # parser_version_set(parser_version_find(pd)) pd } diff --git a/R/utils-navigate-nest.R b/R/utils-navigate-nest.R index b3c193ec9..01a20c926 100644 --- a/R/utils-navigate-nest.R +++ b/R/utils-navigate-nest.R @@ -1,4 +1,3 @@ - #' Find the index of the next or previous non-comment in a parse table. #' @param pd A parse table. #' @param pos The position of the token to start the search from. From 04dcc784631d53c92a7f3195bfa07c383f1340f4 Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 21 Sep 2022 20:42:36 +0200 Subject: [PATCH 12/12] Update environments.R --- R/environments.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/environments.R b/R/environments.R index 7d248c4b4..1ce20dfe8 100755 --- a/R/environments.R +++ b/R/environments.R @@ -43,7 +43,11 @@ parser_version_get <- function() { #' @rdname parser_version_set parser_version_find <- function(pd) { - ifelse(any(pd$token == "equal_assign"), 2, 3) + if (any(pd$token == "equal_assign")) { + 2L + } else { + 3L + } }