From ccberry at ucsd.edu  Wed Oct 15 17:55:53 2014
From: ccberry at ucsd.edu (Charles Berry)
Date: Wed, 15 Oct 2014 15:55:53 +0000
Subject: [Rd] Advice on package design for handling of dots in a formula
References: <0b3f01cfe881$e3613ea0$aa23bbe0$@gmail.com>
Message-ID: <loom.20141015T173808-550@post.gmane.org>

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



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