Skip to content

Commit 1f5e469

Browse files
More adaptation to 4.0+ features (#2606)
* more adaptation to 4.0+ features * better future-proof docs * one more var rename
1 parent d31e0e4 commit 1f5e469

File tree

7 files changed

+28
-48
lines changed

7 files changed

+28
-48
lines changed

NAMESPACE

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
4-
if (getRversion() >= "4.0.0") {
5-
importFrom(tools, R_user_dir)
6-
} else {
7-
importFrom(backports, R_user_dir)
8-
}
93
S3method("[",lints)
104
S3method(as.data.frame,lints)
115
S3method(format,lint)
@@ -183,6 +177,7 @@ importFrom(rex,re_substitutes)
183177
importFrom(rex,regex)
184178
importFrom(rex,rex)
185179
importFrom(stats,na.omit)
180+
importFrom(tools,R_user_dir)
186181
importFrom(utils,capture.output)
187182
importFrom(utils,getParseData)
188183
importFrom(utils,getTxtProgressBar)

R/absolute_path_linter.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
#' * contain at least two path elements, with one having at least two characters and
99
#' * contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
1010
#'
11-
#' @examplesIf getRversion() >= "4.0"
12-
#' # Following examples use raw character constant syntax introduced in R 4.0.
13-
#'
11+
#' @examples
1412
#' # will produce lints
1513
#' lint(
1614
#' text = 'R"--[/blah/file.txt]--"',

R/lintr-package.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,11 @@
1212
#' @importFrom glue glue glue_collapse
1313
#' @importFrom rex rex regex re_matches re_substitutes character_class
1414
#' @importFrom stats na.omit
15+
#' @importFrom tools R_user_dir
1516
#' @importFrom utils capture.output getParseData getTxtProgressBar globalVariables head relist
1617
#' setTxtProgressBar tail txtProgressBar
1718
#' @importFrom xml2 as_list
1819
#' xml_attr xml_children xml_find_all xml_find_chr xml_find_lgl xml_find_num xml_find_first xml_name xml_text
19-
#' @rawNamespace
20-
#' if (getRversion() >= "4.0.0") {
21-
#' importFrom(tools, R_user_dir)
22-
#' } else {
23-
#' importFrom(backports, R_user_dir)
24-
#' }
2520
## lintr namespace: end
2621
NULL
2722

R/utils.R

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,9 @@ platform_independent_sort <- function(x) x[platform_independent_order(x)]
198198
#' Extract text from `STR_CONST` nodes
199199
#'
200200
#' Convert `STR_CONST` `text()` values into R strings. This is useful to account for arbitrary
201-
#' character literals valid since R 4.0, e.g. `R"------[hello]------"`, which is parsed in
202-
#' R as `"hello"`. It is quite cumbersome to write XPaths allowing for strings like this,
203-
#' so whenever your linter logic requires testing a `STR_CONST` node's value, use this
204-
#' function.
201+
#' character literals, e.g. `R"------[hello]------"`, which is parsed in R as `"hello"`.
202+
#' It is quite cumbersome to write XPaths allowing for strings like this, so whenever your
203+
#' linter logic requires testing a `STR_CONST` node's value, use this function.
205204
#' NB: this is also properly vectorized on `s`, and accepts a variety of inputs. Empty inputs
206205
#' will become `NA` outputs, which helps ensure that `length(get_r_string(s)) == length(s)`.
207206
#'
@@ -219,15 +218,14 @@ platform_independent_sort <- function(x) x[platform_independent_order(x)]
219218
#' get_r_string(expr_as_xml, "expr[3]")
220219
#' unlink(tmp)
221220
#'
222-
#' # more importantly, extract strings under R>=4 raw strings
223-
#' @examplesIf getRversion() >= "4.0.0"
224-
#' tmp4.0 <- tempfile()
225-
#' writeLines("c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')", tmp4.0)
226-
#' expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content
227-
#' writeLines(as.character(expr_as_xml4.0))
228-
#' get_r_string(expr_as_xml4.0, "expr[2]")
229-
#' get_r_string(expr_as_xml4.0, "expr[3]")
230-
#' unlink(tmp4.0)
221+
#' # more importantly, extract raw strings correctly
222+
#' tmp_raw <- tempfile()
223+
#' writeLines("c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')", tmp_raw)
224+
#' expr_as_xml_raw <- get_source_expressions(tmp_raw)$expressions[[1L]]$xml_parsed_content
225+
#' writeLines(as.character(expr_as_xml_raw))
226+
#' get_r_string(expr_as_xml_raw, "expr[2]")
227+
#' get_r_string(expr_as_xml_raw, "expr[3]")
228+
#' unlink(tmp_raw)
231229
#'
232230
#' @export
233231
get_r_string <- function(s, xpath = NULL) {

R/zzz.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,8 @@ settings <- new.env(parent = emptyenv())
295295
toset <- !(names(op_lintr) %in% names(op))
296296
if (any(toset)) options(op_lintr[toset])
297297

298-
# R>=4.0.0: deparse1
299298
# R>=4.1.0: ...names
300-
backports::import(pkgname, c("deparse1", "...names"))
299+
backports::import(pkgname, "...names")
301300

302301
utils::assignInMyNamespace("default_settings", list(
303302
linters = default_linters,

man/absolute_path_linter.Rd

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

man/get_r_string.Rd

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

0 commit comments

Comments
 (0)