Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Generated by roxygen2: do not edit by hand


if (getRversion() >= "4.0.0") {
importFrom(tools, R_user_dir)
} else {
importFrom(backports, R_user_dir)
}
S3method("[",lints)
S3method(as.data.frame,lints)
S3method(format,lint)
Expand Down Expand Up @@ -183,6 +177,7 @@ importFrom(rex,re_substitutes)
importFrom(rex,regex)
importFrom(rex,rex)
importFrom(stats,na.omit)
importFrom(tools,R_user_dir)
importFrom(utils,capture.output)
importFrom(utils,getParseData)
importFrom(utils,getTxtProgressBar)
Expand Down
4 changes: 1 addition & 3 deletions R/absolute_path_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#' * contain at least two path elements, with one having at least two characters and
#' * contain only alphanumeric chars (including UTF-8), spaces, and win32-allowed punctuation
#'
#' @examplesIf getRversion() >= "4.0"
#' # Following examples use raw character constant syntax introduced in R 4.0.
#'
#' @examples
#' # will produce lints
#' lint(
#' text = 'R"--[/blah/file.txt]--"',
Expand Down
7 changes: 1 addition & 6 deletions R/lintr-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,11 @@
#' @importFrom glue glue glue_collapse
#' @importFrom rex rex regex re_matches re_substitutes character_class
#' @importFrom stats na.omit
#' @importFrom tools R_user_dir
#' @importFrom utils capture.output getParseData getTxtProgressBar globalVariables head relist
#' setTxtProgressBar tail txtProgressBar
#' @importFrom xml2 as_list
#' xml_attr xml_children xml_find_all xml_find_chr xml_find_lgl xml_find_num xml_find_first xml_name xml_text
#' @rawNamespace
#' if (getRversion() >= "4.0.0") {
#' importFrom(tools, R_user_dir)
#' } else {
#' importFrom(backports, R_user_dir)
#' }
## lintr namespace: end
NULL

Expand Down
24 changes: 11 additions & 13 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,9 @@ platform_independent_sort <- function(x) x[platform_independent_order(x)]
#' Extract text from `STR_CONST` nodes
#'
#' Convert `STR_CONST` `text()` values into R strings. This is useful to account for arbitrary
#' character literals valid since R 4.0, e.g. `R"------[hello]------"`, which is parsed in
#' R as `"hello"`. It is quite cumbersome to write XPaths allowing for strings like this,
#' so whenever your linter logic requires testing a `STR_CONST` node's value, use this
#' function.
#' character literals, e.g. `R"------[hello]------"`, which is parsed in R as `"hello"`.
#' It is quite cumbersome to write XPaths allowing for strings like this, so whenever your
#' linter logic requires testing a `STR_CONST` node's value, use this function.
#' NB: this is also properly vectorized on `s`, and accepts a variety of inputs. Empty inputs
#' will become `NA` outputs, which helps ensure that `length(get_r_string(s)) == length(s)`.
#'
Expand All @@ -219,15 +218,14 @@ platform_independent_sort <- function(x) x[platform_independent_order(x)]
#' get_r_string(expr_as_xml, "expr[3]")
#' unlink(tmp)
#'
#' # more importantly, extract strings under R>=4 raw strings
#' @examplesIf getRversion() >= "4.0.0"
#' tmp4.0 <- tempfile()
#' writeLines("c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')", tmp4.0)
#' expr_as_xml4.0 <- get_source_expressions(tmp4.0)$expressions[[1L]]$xml_parsed_content
#' writeLines(as.character(expr_as_xml4.0))
#' get_r_string(expr_as_xml4.0, "expr[2]")
#' get_r_string(expr_as_xml4.0, "expr[3]")
#' unlink(tmp4.0)
#' # more importantly, extract raw strings correctly
#' tmp_raw <- tempfile()
#' writeLines("c(R'(a\\b)', R'--[a\\\"\'\"\\b]--')", tmp_raw)
#' expr_as_xml_raw <- get_source_expressions(tmp_raw)$expressions[[1L]]$xml_parsed_content
#' writeLines(as.character(expr_as_xml_raw))
#' get_r_string(expr_as_xml_raw, "expr[2]")
#' get_r_string(expr_as_xml_raw, "expr[3]")
#' unlink(tmp_raw)
#'
#' @export
get_r_string <- function(s, xpath = NULL) {
Expand Down
3 changes: 1 addition & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ settings <- new.env(parent = emptyenv())
toset <- !(names(op_lintr) %in% names(op))
if (any(toset)) options(op_lintr[toset])

# R>=4.0.0: deparse1
# R>=4.1.0: ...names
backports::import(pkgname, c("deparse1", "...names"))
backports::import(pkgname, "...names")

utils::assignInMyNamespace("default_settings", list(
linters = default_linters,
Expand Down
5 changes: 1 addition & 4 deletions man/absolute_path_linter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 12 additions & 14 deletions man/get_r_string.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.