Skip to content
Prev 199962 / 398502 Next

Is there a way to specify drop=FALSE as the global default?

The following code won't change the defaults, but it would at least
let you know when you're making the mistake:

trace_all <- function(fs, tracer) {
  lapply(fs, trace, exit = tracer, print=FALSE)
  invisible()
}

functions_with_arg <- function(arg, pos) {
  fs <- ls(pos=pos)
  present <- unlist(lapply(fs, function(x)
    is.function(get(x)) &&  !is.null(formals(x)[[arg]])))

  fs[present]
}

trace_all(
  functions_with_arg("drop", "package:base"),
  quote(if (drop) warning("drop = TRUE", call. = F))
)
[1] 6
Warning message:
drop = TRUE

Unfortunately it doesn't pick up on the generic [ because it is a primitive.

Hadley