Skip to content

How do I call a masked function in a package without a namespace?

2 messages · Dirk Koschuetzki, Gabor Grothendieck

#
Hello,

I work with two packages sna and graph from CRAN resp. Bioconductor. Both  
packages have a function called "degree". Therefore one of the functions  
is masked by the other and which one gets called depends on the order of  
loading. The problem is that both package do not have a namespace,  
therefore calling the masked function with "package::degree" does not  
work. See the following transcript:

$ R --vanilla

[[ Running on Debian Sarge ]]

R : Copyright 2004, The R Foundation for Statistical Computing
Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0
[...]
Loading required package: cluster
Loading required package: Ruuid
Creating a new generic function for "print" in "Ruuid"
Loading required package: Biobase
Loading required package: tools
Welcome to Bioconductor
          Vignettes contain introductory material.  To view,
          simply type: openVignette()
          For details on reading vignettes, see
          the openVignette help page.
[1] "last.warning" "degree"       "body<-"       "print"        "split"
[6] "union"
Error in loadNamespace(name) : package 'sna' does not have a name space
Error in loadNamespace(name) : package 'graph' does not have a name space
Error in loadNamespace(name) : package 'sna' does not have a name space
Error in loadNamespace(name) : package 'graph' does not have a name space


Is there a way to call the masked function via a different way?
And I wold like to create my own function degree which will of course  
masked both functions and should therefore be able to call both functions.

Thanks for any hint!

Cheers,
Dirk
#
Dirk Koschuetzki <dkoschuetzki <at> gmx.de> writes:

: 
: Hello,
: 
: I work with two packages sna and graph from CRAN resp. Bioconductor. Both  
: packages have a function called "degree". Therefore one of the functions  
: is masked by the other and which one gets called depends on the order of  
: loading. The problem is that both package do not have a namespace,  
: therefore calling the masked function with "package::degree" does not  
: work. See the following transcript:
: 
: $ R --vanilla
: 
: [[ Running on Debian Sarge ]]
: 
: R : Copyright 2004, The R Foundation for Statistical Computing
: Version 2.0.1  (2004-11-15), ISBN 3-900051-07-0
: [...]
: 
: > library("sna")
: > library("graph")
: Loading required package: cluster
: Loading required package: Ruuid
: Creating a new generic function for "print" in "Ruuid"
: Loading required package: Biobase
: Loading required package: tools
: Welcome to Bioconductor
:           Vignettes contain introductory material.  To view,
:           simply type: openVignette()
:           For details on reading vignettes, see
:           the openVignette help page.
: > conflicts()
: [1] "last.warning" "degree"       "body<-"       "print"        "split"
: [6] "union"
: 
: > sna::degree()
: Error in loadNamespace(name) : package 'sna' does not have a name space
: > graph::degree()
: Error in loadNamespace(name) : package 'graph' does not have a name space
: > sna:::degree
: Error in loadNamespace(name) : package 'sna' does not have a name space
: > graph:::degree
: Error in loadNamespace(name) : package 'graph' does not have a name space
: 
: Is there a way to call the masked function via a different way?
: And I wold like to create my own function degree which will of course  
: masked both functions and should therefore be able to call both functions.
: 

The following looks up the position of the graph package on the
search path and gets degree specifically from there,
invokes it with the indicates arguments.

graph.degree <- function(...)
   get("degree", grep("package:graph$", search()))(...)