In my genridge package, I define a function ridge() for ridge regression, creating objects of class 'ridge' that I intend to enhance. In a documentation example, I want to use some functions from the car package. However, that package requires survival, which also includes a ridge() function, for coxph models. So, once I require(car) my ridge() function is masked, which means I have to use the awkward form below in my .Rd files. ridgemod <- genridge::ridge(...) I tried to detach survival, but that doesn't work: > detach("package:survival") Error: package ?survival? is required by ?car? so will not be detached I don't see any solution to this, other than (a) renaming my ridge() to something else -- don't want to do this (b) use \dontrun{} for the examples that use car Or, is there some other way? -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street Web: http://www.datavis.ca Toronto, ONT M3J 1P3 CANADA
On 11-11-24 4:44 PM, Michael Friendly wrote:> In my genridge package, I define a function ridge() for ridge > regression, creating objects of class 'ridge' > that I intend to enhance. > > In a documentation example, I want to use some functions from the car > package. However, that package > requires survival, which also includes a ridge() function, for coxph > models. So, once I require(car) > my ridge() function is masked, which means I have to use the awkward > form below in my .Rd files. > > ridgemod<- genridge::ridge(...) > > I tried to detach survival, but that doesn't work: > > > detach("package:survival") > Error: package ?survival? is required by ?car? so will not be detached > > I don't see any solution to this, other than > (a) renaming my ridge() to something else -- don't want to do this > (b) use \dontrun{} for the examples that use car > > Or, is there some other way?Not really. I'd say the renaming is the preferred way to go, but you might also be able to convince Terry Therneau (survival author) to make ridge() a generic, so your method is called for your objects, and his is called for others. Duncan Murdoch
The ridge() function was put into the survival package as a simple example of what a user could do with penalized functions. It's not a "serious" function, and I'd be open to any suggestions for change. Actually, for any L2 penalty + Cox model one is now better off using coxme as the maximization process is much better thought out there. I'd be happy to remove ridge from survival -- except that there are bound to be lots of folks using the function and any such changes (even good ones) to the survival package are fraught with peril. Duncan: this raises a larger point. I've often wished that I could have "namespace" like rules apply to formulas. Using survival again, when I implemented gam-like smooths I had to create "pspline" rather than use the more natural "s()" notation. In survival, it would be good to do this for ridge, cluster, pspline, and frailty; all of whom depend deeply on a coxph context. It would also solve a frailty() problem of long standing, that when used in survreg only a subset of the frailty options make sense; this is documented in the help file but catches users again and again. Terry Therneau On Fri, 2011-11-25 at 12:00 +0100, r-devel-request at r-project.org wrote:> > In my genridge package, I define a function ridge() for ridge > > regression, creating objects of class 'ridge' > > that I intend to enhance. > > > > In a documentation example, I want to use some functions from the > car > > package. However, that package > > requires survival, which also includes a ridge() function, for coxph > > models. So, once I require(car) > > my ridge() function is masked, which means I have to use the awkward > > form below in my .Rd files. > > > > ridgemod<- genridge::ridge(...) > > > > I tried to detach survival, but that doesn't work: > > > > > detach("package:survival") > > Error: package ?survival? is required by ?car? so will not be > detached > > > > I don't see any solution to this, other than > > (a) renaming my ridge() to something else -- don't want to do this > > (b) use \dontrun{} for the examples that use car > > > > Or, is there some other way? > > Not really. I'd say the renaming is the preferred way to go, but you > might also be able to convince Terry Therneau (survival author) to > make > ridge() a generic, so your method is called for your objects, and his > is > called for others. > > Duncan Murdoch >
Hi Michael, As promised, I've moved survival to Suggests in the development version of the car package on R-Forge. AFAICS, this doesn't cause any problems (and should solve your problem). I incidentally added Anova() and linearHypothesis() methods for svyglm objects, and placed the survey package under Suggests. Best, John> -----Original Message----- > From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r- > project.org] On Behalf Of John Fox > Sent: November-25-11 11:47 AM > To: 'Michael Friendly' > Cc: 'Terry Therneau'; r-devel at r-project.org > Subject: Re: [Rd] How to deal with package conflicts > > Hi Michael, > > I'll look into moving survival to suggests (this weekend, if I have > time), but that doesn't address the more general issue. > > Best, > John > > > -----Original Message----- > > From: Michael Friendly [mailto:friendly at yorku.ca] > > Sent: November-25-11 10:43 AM > > To: Terry Therneau > > Cc: r-devel at r-project.org; John Fox; Duncan Murdoch > > Subject: Re: [Rd] How to deal with package conflicts > > > > On 11/25/2011 9:10 AM, Terry Therneau wrote: > > > The ridge() function was put into the survival package as a simple > > > example of what a user could do with penalized functions. It's not > > > a "serious" function, and I'd be open to any suggestions for > change. > > > > > > Actually, for any L2 penalty + Cox model one is now better off > using > > > coxme as the maximization process is much better thought out there. > > > I'd be happy to remove ridge from survival -- except that there are > > > bound to be lots of folks using the function and any such changes > > > (even good > > > ones) to the survival package are fraught with peril. > > Duncan provided one suggestion: make ridge() an S3 generic, and > > rename > > ridge() > > to ridge.coxph(), but this won't work, since you use ridge() inside > > coxph() and > > survreg() to add a penalty term in the model formula. > > Another idea might be simply to not export ridge(), but I have the > > feeling this will break your R CMD checks. > > > > Alternatively, my particular problem (wanting to use car::vif in my > > package documentation) would be solved if John Fox considered making > > making survival a Suggests: > > package rather than a > > Depends: one. This might work, since survival is only referenced in > > car by providing Anova() methods for coxph models. > > > > I think all of this raises a general issue of unintended consequences > > of "package bloat," where > > (a) Depends: packages are forced to load by require()/library(), > > whether they are really needed or not; > > (b) There is nothing like require(car, depends=FALSE) to circumvent > > this; > > (c) Once a require()'d package is loaded, it cannot be unloaded; > > (d) AFAIK, there is no way for a package author to override the > > masking of functions or data provided by other other packages, except > > by using > > mypackage::myfun() calls. > > > > To me this seems to be a flaw in the namespace mechanism. > > > > best, > > -Michael > > > > > > > > > > > > > > > > -- > > Michael Friendly Email: friendly AT yorku DOT ca > > Professor, Psychology Dept. > > York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 > > 4700 Keele Street Web: http://www.datavis.ca > > Toronto, ONT M3J 1P3 CANADA > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel