[R] New-user support package - suggestions?

hadley wickham h.wickham at gmail.com
Thu May 4 15:09:44 CEST 2006


I started on such a project a while ago for my personal use when
creating packages.  Often I forget to use na.rm and never test my
functions with code containing missing values, and then later on have
to search back through my code and ensure I've used na.rm=TRUE
everywhere.

I didn't get very far, because at that point my code was segfaulting R
on the mac.  I've just re-looked at my code and it seems to run ok
now.  This might at least get you started:


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")))

#trace_all(functions_with_arg("na.rm", "package:base"), quote(if
(!na.rm) warning("na.rm = FALSE")))

Other functionality I'd like to see in such a package (from my needs
as a developer) would be:

 * enforcing use of TRUE and FALSE (would just need to copy code used
when running examples in R CMD check)

 * always using drop = FALSE in [

But they should take about 15 minutes to implement, so I'm not sure
what you'd do for the rest of the 6 weeks.

Hadley




More information about the R-help mailing list