[R] Seg fault with trace

hadley wickham h.wickham at gmail.com
Mon Dec 26 16:15:48 CET 2005


(Under 2.2.0, Mac)

I have been unable to reduce this to a simple case, so I'll include my
full code, and my intentions.  The problem I'm trying to solve is that
while many defaults (eg. na.rm=F, drop=T) make sense for interactive
programming, they tend to be a bit of a pain when developing a
package.  For example, I often forget to use drop=FALSE, only test
with multiple columns and then spend ages trying to figure out why it
doesn't work when I use the function with a single column. The idea of
the functions below is to automatically warn me when I do something
like that.

trace_all <- function(fs, tracer) {
	sapply(fs, trace, tracer=tracer, print=FALSE)
	return()
}

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(list("sum"), quote(if (!na.rm) warning("na.rm = FALSE")))
# Works
trace_all(functions_with_arg("na.rm", "package:base"), quote(if
(!na.rm) warning("na.rm = FALSE")))
# Segfaults

I'd be happy to explore alternative approaches, especially since this
approach modifies the functions in their original namespaces, and I
only want to see the warnings when my functions use these functions.

Hadley




More information about the R-help mailing list