Skip to main content

FRAME_CALL_HELPER

Constant FRAME_CALL_HELPER 

Source
const FRAME_CALL_HELPER: &str = "# Internal helper: the call a generated S3 method\'s conditions report, from\n# the method\'s frame (`environment()`, which the method passes as `.call`).\n# Under R\'s dispatch the method\'s own call names the method,\n# `summary.cls(x, a = 1)`, and `.Generic` is bound in its frame; the result\n# names the generic the user called instead: `summary(x, a = 1)`, `x[i]`,\n# `x + 1` for an `Ops` method. For a replacement generic (`$<-`, `[[<-`, `[<-`,\n# `names<-`, ...), which R calls as `` `$<-.cls`(`*tmp*`, name, value = <v>) ``,\n# the result is the assignment as written, `x$name <- value`, with the\n# method\'s first formal as the receiver and the symbol `value` in place of the\n# value, so a large value is never deparsed into the call. `rbind()` and\n# `cbind()` dispatch from C and call the method as `rbind(deparse.level, ...)`;\n# the result is the user\'s call to base\'s `rbind` / `cbind` instead. A method\n# called directly by name has no `.Generic` and keeps its own call. The frame is\n# looked up among the live frames, so the helper serves the method\'s own\n# checks, the raise helper and the conditions deferred while the method\'s\n# `.Call()` runs; a frame that is no longer live gives NULL.\n.miniextendr_frame_call <- function(env) {\n  frames <- sys.frames()\n  i <- length(frames)\n  while (i > 0L && !identical(frames[[i]], env)) i <- i - 1L\n  if (i == 0L) return(NULL)\n  call <- sys.call(i)\n  generic <- env[[\".Generic\"]]\n  if (is.null(generic) && length(call) == 3L && identical(call[[2L]], quote(deparse.level)) && identical(call[[3L]], quote(...))) {\n    bind <- if (identical(call[[1L]], quote(rbind))) base::rbind else if (identical(call[[1L]], quote(cbind))) base::cbind\n    p <- sys.parents()[[i]]\n    if (!is.null(bind) && p > 0L && identical(sys.function(p), bind)) {\n      user <- sys.call(p)\n      user[[1L]] <- call[[1L]]\n      return(user)\n    }\n  }\n  if (!is.character(generic) || length(generic) != 1L) return(call)\n  if (length(call) > 1L && identical(call[[2L]], quote(`*tmp*`))) {\n    call[[2L]] <- as.name(names(formals(sys.function(i)))[[1L]])\n  }\n  if (!endsWith(generic, \"<-\")) {\n    call[[1L]] <- as.name(generic)\n    return(call)\n  }\n  call$value <- NULL\n  call[[1L]] <- as.name(substr(generic, 1L, nchar(generic) - 2L))\n  call(\"<-\", call, quote(value))\n}\n";
Expand description

The preamble’s .miniextendr_frame_call binding of frame_call_helper_fn!, with its comment block, as written by write_r_wrappers_to_file.