Skip to content
Prev 60488 / 63424 Next

Parser oddity with <- and =

In R-4.1.2 and R-devel from two weeks ago I do not get the `<-<-`:
expression: structure(expression(a <- b = c), sr ...
  language: a <- b = c
    symbol: =
    language: a <- b
      symbol: <-
      symbol: a
      symbol: b
    symbol: c
c)")[[1]])
[1] TRUE

str.language() is a rudimentary parse tree displayer:

str.language <- function(expr, name = "", indent = 0)
{
    trim... <- function(string, width.cutoff) {
        if (nchar(string) > width.cutoff) {
            string <- sprintf("%.*s ...", width.cutoff-4, string)
        }
        string
    }
    cat(sep="", rep("  ", indent), typeof(expr), ": ",
        if(length(name)==1 && nzchar(name)) { paste0(name, " = ") },
        trim...(deparse1(expr, width.cutoff=40), width.cutoff=40),
        "\n")
    if (is.function(expr)) {
        str.language(formals(expr), name="[formals]", indent = indent + 1)
        str.language(body(expr), name="[body]", indent = indent + 1)
    } else if (is.recursive(expr)) {
        expr <- as.list(expr)
        nms <- names(expr)
        for (i in seq_along(expr)) {
            str.language(expr[[i]], name=nms[[i]], indent = indent + 1)
        }
    }
    invisible(expr)
}


-Bill

On Fri, Feb 4, 2022 at 9:34 AM Duncan Murdoch <murdoch.duncan at gmail.com>
wrote: