jlmelville / uwot

An R package implementing the UMAP dimensionality reduction method.
https://jlmelville.github.io/uwot/
GNU General Public License v3.0
322 stars 31 forks source link

Found more than one class "dist" in cache #121

Closed AndiMunteanu closed 8 months ago

AndiMunteanu commented 8 months ago

Hello!

Thank you for creating and mantaining this very useful package! I noticed this warning that pops up when creating the UMAP: Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics' Also defined by 'spam'

This is an example that could help reproduce the problem:

library(BiocGenerics)
library(spam)
library(uwot)
uwot::umap(matrix(runif(300), ncol = 10))

The spam package is usually loaded together with Seurat and BiocGenerics with rhdf5, so at least in my use-case I can't avoid getting this warning. I think that this warning is caused by an ambiguous definition of the dist class in the neghbors.R and uwot.R files, more precisely on these lines:

https://github.com/jlmelville/uwot/blob/3bff01f86758151880c17a3ca1db0665aa9cf8b7/R/neighbors.R#L14

https://github.com/jlmelville/uwot/blob/3bff01f86758151880c17a3ca1db0665aa9cf8b7/R/uwot.R#L3204

https://github.com/jlmelville/uwot/blob/3bff01f86758151880c17a3ca1db0665aa9cf8b7/R/uwot.R#L4266

Replacing "dist" with "stats::dist" in these lines should fix this issue.

Thank you!

jlmelville commented 8 months ago

Thanks for letting me know about this. Unfortunately, the proposed fix doesn't quite work.

diris <- stats::dist(iris[1:10, -5])

methods::is(diris, "dist")
[1] TRUE

methods::is(diris, "stats::dist")
[1] FALSE

This may require some research.

AndiMunteanu commented 8 months ago

Thank you for the very quick response! You are right, sorry for suggesting a wrong solution!

Would replacing methods::is with inherits or something more custom (like attributes(diris)$class == "dist") keep the code consistent and remove the warning?

jlmelville commented 8 months ago

inherits seems to do the trick. Thank you for the suggestion. A fix has been pushed to master and this should be in the next CRAN release.

AndiMunteanu commented 8 months ago

Thank you very much, your work is much appreciated! I will close this issue, since the problem was fixed.