Søren Højsgaard
2007-Mar-20 22:25 UTC
[R] Over-writing functions from other packages? What is a good strategy??
I am writing a package which uses the Rgraphviz package which in turn uses the graph package, but my question does not (I believe) pertain specifically to the these packages so therefore I dare to post the question here: I my package I have a function "edges" which works on some graphs I have defined. However, there is also a function "edges" (or rather a generic method) in the graph package (seemingly written in S4). When I load my package the Rgraphviz package is automatically loaded, but this means that the edges method of the the graph package "overrides" the edge function in my package. Is there a way of avoiding this? If there is, I guess that it is a dangerous path to take? But if so, what else is a good strategy to take? Regards S?ren
Gabor Grothendieck
2007-Mar-21 01:59 UTC
[R] Over-writing functions from other packages? What is a good strategy??
Could you call yours Edges? On 3/20/07, S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> wrote:> I am writing a package which uses the Rgraphviz package which in turn uses the graph package, but my question does not (I believe) pertain specifically to the these packages so therefore I dare to post the question here: > > I my package I have a function "edges" which works on some graphs I have defined. However, there is also a function "edges" (or rather a generic method) in the graph package (seemingly written in S4). When I load my package the Rgraphviz package is automatically loaded, but this means that the edges method of the the graph package "overrides" the edge function in my package. > > Is there a way of avoiding this? If there is, I guess that it is a dangerous path to take? But if so, what else is a good strategy to take? > > Regards > S?ren > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Seth Falcon
2007-Mar-21 03:34 UTC
[R] Over-writing functions from other packages? What is a good strategy??
S?ren H?jsgaard <Soren.Hojsgaard at agrsci.dk> writes:> I am writing a package which uses the Rgraphviz package which in > turn uses the graph package, but my question does not (I believe) > pertain specifically to the these packages so therefore I dare to > post the question here: > > I my package I have a function "edges" which works on some graphs I > have defined. However, there is also a function "edges" (or rather a > generic method) in the graph package (seemingly written in S4).Yes, edges is a generic function defined by the graph package. With methods for various graph representation classes.> I load my package the Rgraphviz package is automatically loaded, but > this means that the edges method of the the graph package > "overrides" the edge function in my package. > > Is there a way of avoiding this? If there is, I guess that it is a > dangerous path to take? But if so, what else is a good strategy to > take?I'm pretty sure this is resolved by adding a NAMESPACE file to your package (see the Writing R Extensions Manual for details). I made a little test package that has Rgraphviz in Depends, defines an edges function and exports it in its NAMESPACE file. When I load this package, edges is the one from my test package and graph::edges is the one from graph. It won't solve your problem in general, but I will also look into having Rgraphviz only import graph and not Depend on it. This would avoid graph::edges polluting the search path when Rgraphviz gets loaded. This is a reason that import might be preferred over Depends for packages that have namespaces. Finally, if you were depending on graph and not Rgraphviz, then you could rename graph::edges when you import it in your NAMESPACE file: importFrom("graph", someOtherName=edges) + seth -- Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center http://bioconductor.org
Alberto Monteiro
2007-Mar-21 11:06 UTC
[R] Over-writing functions from other packages? What is a good strategy??
Gabor Grothendieck wrote:> > Could you call yours Edges? >Is it a good idea to have two different functions, whose name differs by case sensitivity? I believe this is a shortcut to Chaos :-) IMHO, case sensitivity should _only_ be used for aesthetical purposes, else it may result in errors that are very difficult to find. Of course, YKMV.[*] Alberto Monteiro [*] I always use S.I. units :-)
Gabor Grothendieck
2007-Mar-21 12:18 UTC
[R] Over-writing functions from other packages? What is a good strategy??
Sometimes but its also easy to forget about simple solutions. On 3/21/07, Alberto Monteiro <albmont at centroin.com.br> wrote:> Gabor Grothendieck wrote: > > > > Could you call yours Edges? > > > Is it a good idea to have two different functions, whose name > differs by case sensitivity? I believe this is a shortcut to > Chaos :-) > > IMHO, case sensitivity should _only_ be used for aesthetical > purposes, else it may result in errors that are very difficult > to find. Of course, YKMV.[*] > > Alberto Monteiro > > [*] I always use S.I. units :-) > >