Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R S3 method not exported from namespace

Why do I have this error message :

> vegan::reorder.hclust
Error: 'reorder.hclust' is not an exported object from 'namespace:vegan'

While this S3 method is well available. For example if I type help(reorder.hclust, package = "vegan") I obtain the intended help page and vegan:::reorder.hclust displays the source code of the function on the console...
Also the NAMESPACE file of my vegan installation contains S3method(reorder, hclust).

I would like to use this function in another package were I need to import it or use vegan::reorder.hclust

> sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.4 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=fr_BE.UTF-8       LC_NUMERIC=C               LC_TIME=fr_BE.UTF-8       
 [4] LC_COLLATE=fr_BE.UTF-8     LC_MONETARY=fr_BE.UTF-8    LC_MESSAGES=fr_BE.UTF-8   
 [7] LC_PAPER=fr_BE.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=fr_BE.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] MASS_7.3-49     compiler_3.4.3  Matrix_1.2-11   parallel_3.4.3  tools_3.4.3    
 [6] mgcv_1.8-23     yaml_2.1.18     nlme_3.1-131.1  grid_3.4.3      permute_0.9-4  
[11] vegan_2.4-6     cluster_2.0.6   lattice_0.20-35
like image 803
Gilles Avatar asked Oct 17 '22 21:10

Gilles


1 Answers

You get that error because vegan doesn't export that function. It can give help for things that aren't exported. Using three colons vegan:::reorder.hclust displays internal functions that are not exported; normally you should avoid using those.

However, when the vegan package is loaded, its reorder.hclust function will be added to the methods table for reorder. So you just need to make sure that it is loaded, and then if hc is an hclust object, reorder(hc) will call the reorder.hclust method. You can do this by putting requireNamespace("vegan") into your code, or importing something from vegan in your NAMESPACE file.

If there are two reorder.hclust methods (defined by different packages that are both loaded), then I don't think there's an easy way for you to specify the vegan one other than using vegan:::reorder.hclust, which CRAN will object to. You would need to ask the vegan maintainer to export their function so you could access it using the legal vegan::reorder.hclust, or copy the code into your own package, or some other inconvenient approach.

like image 158
user2554330 Avatar answered Oct 21 '22 00:10

user2554330