Skip to content
Prev 62806 / 63424 Next

Depends: R (>= 4.1) for packages that use |> and \(...)

Many thanks to Henrik for remembering the report in Bugzilla and to
Kurt for implementing the change and finding out the true number of
affected packages.

On Wed, 22 Jan 2025 15:34:41 -0500
Ian Farm <ian.farm at maine.edu> wrote:

            
That's a good find! For the R >= 4.2 syntax, we only need to check for
getParseData(...)$token %in% 'PLACEHOLDER'. The R >= 4.3 syntax feature
is harder to test for:
I think it might be possible to parse(text = paste('PLACEHOLDER |>',
grandparent_expression)) and then look at the top-level function in the
call, but that feels quite fragile:

x <- utils::getParseData(parse(f, keep.source = TRUE))
i <- x$token %in% "PLACEHOLDER"
pi <- x[i, "parent"]
ppi <- x[x$id %in% pi, "parent"]
placeholder_expressions <- utils::getParseText(x, ppi)
extractor_used <- vapply(placeholder_expressions, function(src) {
 toplevel <- parse(text = paste("PLACEHOLDER |> ", src))[[1]][[1]]
 identical(toplevel, quote(`$`)) ||
  identical(toplevel, quote(`[`)) ||
  identical(toplevel, quote(`[[`))
}, FALSE)

Alternatively, we may find the first child of the grandparent of the
placeholder. If it's the placeholder expression, then the pipe must be
of the form ...|> _..., which is the R >= 4.3 syntax:

x <- utils::getParseData(parse(f, keep.source = TRUE))
i <- x$token %in% "PLACEHOLDER"
vapply(which(i), function(i) {
 pi <- x[i, "parent"]
 ppi <- x[x$id %in% pi, "parent"]
 cppi <- x[x$parent %in% ppi, "id"]
 min(cppi) == pi
}, FALSE)