Skip to content

Commit

Permalink
better future-proof docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelChirico committed Jun 13, 2024
1 parent 3906bea commit 30a0597
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
23 changes: 11 additions & 12 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,14 +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
#' 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(tmp4.0)$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
23 changes: 11 additions & 12 deletions man/get_r_string.Rd

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

0 comments on commit 30a0597

Please sign in to comment.