[R] Introductory Resources

Duncan Murdoch murdoch at stats.uwo.ca
Fri Jun 6 19:51:15 CEST 2003


On Fri, 6 Jun 2003 12:04:47 -0400 , you wrote in message
<3598558AD728D41183350008C7CF291C0F16B7F6 at exchange1.ahrq.gov>:

>1) I want a test suite for R.  I noted in the messages (Date: Mon Feb 24
>2003 - 22:18:03 EST) that Prof Ripley wrote "Well, R itself has lots of
>tests in its test suite (see directory tests in the sources) packages..."
>but I was too stupid to find them.  
>Q1: Can someone provide directions to this test suite that even an idiot can
>follow?

You need to download the source code to R from CRAN (e.g.
cran.mirrors.pair.com), it's not in the precompiled binaries.  You'll
find the tests in the "tests" subdirectory.  They consist of pairs of
foo.R and foo.Rout.save files.  When you run the tests via "make
check", foo.Rout will be produced, and you'll be warned about
differences from foo.Rout.save.

Testing also runs almost all of the examples in every help file, and
aborts if any generate errors (or warnings, I forget just now...).
Package writers can include their own test scripts and saved output
files.

>Q2: Can the missing defaults be set globally for all functions.  In other
>words, I want the default for how to treat NAs in all functions to be set at
>startup.

option(na.action=<some function>) will control how all well-behaved
functions handle NAs, but not all functions are well-behaved.
Complain about those that should be but aren't (to the package
maintainer in case of a contributed package, here or to r-bugs in case
of a built-in package).

>3)  What I really want to do is pass a function name and extra arguments to
>another function.  For example, in Splus, you can pass a function such as
>median to the bootstrap function.  The bootstrap function says that you can
>pass arguments to the median function through the bootstrap function but
>unfortunately I could never make this work.  This functionality would
>probably solve most of my NA problems if I could make it work.  (I don't
>seem to be able to properly use the ellipses:)
>Pseudo-Example: The Splus bootstrap can be called as
>Bootstrap(variable-name, median, sampler=sample-function, na.rm=T)
>But I never figured out how to pass the na.rm=T as an argument to median so
>that the function being bootstrapped is median(variable-name, na.rm=T).

>Q3: Is there some way in R to pass alternative arguments through a function
>to another?

Yes, I think this is similar in R and S-PLUS, so you might run into
the same problems.  Generally it's easy using ellipses, but if the
argument name for your function happens to be the prefix of an
argument name for the Bootstrap function, then you'll get a match
there, instead of where you want it.  

For example, in R bootstrapping can be done using the function boot()
in library(boot).  It has arguments:

 boot(data, statistic, R, sim="ordinary", stype="i", 
          strata=rep(1,n), L=NULL, m=0, weights=NULL, 
          ran.gen=function(d, p) d, mle=NULL, ...)

The ellipses will pass other arguments to the function passed as the
statistic argument, but if you named them "str" they'd match "strata"
instead of being passed to "...".  Thus

 boot(vname, median, na.rm=T)

should work, but 

 myfunc <- function(x, str) median(x, na.rm=str)

 boot(vname, myfunc, str=T)

would not.


>4)    Any general thoughts on Splus versus R that you are willing to share?

S-PLUS has a more polished GUI.  R is more responsive to bug reports.

Duncan Murdoch




More information about the R-help mailing list