[Rd] Advice on package design for handling of dots in a formula

Charles Berry ccberry at ucsd.edu
Wed Oct 15 17:55:53 CEST 2014


Greg Ridgeway <gregridgeway <at> gmail.com> writes:

> 
> I am working on a new package, one in which the user needs to specify the
> role that different variables play in the analysis. Where I'm stumped is >
the best way to have users specify those roles.

[delete discussion of dot in formula and specials]
> 
> Does anyone have advice on how best to handle this? 
> 1. Tell my tester "Tough, you can't use dots in a formula in my
> package".essentially what the survey package seems to do. Encourage the 
> use of survey::make.formula()?
> 2. Fix Approach #1 to search for duplicates in the weights, observation 
> ID,and strata parameters. Any elegant ways to do that?
> 3. Fix Approach #2, the coxph style, to try to remove redundant 
> covariates.
> Not sure if there's a graceful way not involving string matching
> 4. Any existing elegant approaches to interpreting the dot? Or should I 
> just do string matching to delete duplicate variables from the terms 
> object.
> 

See ?terms.formula and note the `allowDotAsName' arg.

> trms <- terms(y~speshul(x)+.,allowDotAsName=TRUE,specials="speshul")
> attr(trms,"term.labels")
[1] "speshul(x)" "."         

See ?all.vars

> all.vars(trms)
[1] "y" "x" "."
> setdiff( all.vars(trms) , "." )
[1] "y" "x"
> 

HTH,

Chuck



More information about the R-devel mailing list