gdkrmr / dimRed

A Framework for Dimensionality Reduction in R
https://www.guido-kraemer.com/software/dimred/
GNU General Public License v3.0
73 stars 15 forks source link

could not find function "dimRedMethodList" #6

Closed topepo closed 7 years ago

topepo commented 7 years ago

I'm creating a package that imports dimRed and I'm getting an error ("Error in eval(expr, envir, enclos) : could not find function "dimRedMethodList") when invoking this code:

#' @importFrom dimRed Isomap dimRedData embed

foo <- function(x, training, ...) {
  imap <- embed(dimRedData(training)), 
                "Isomap", knn = x$options$knn, 
                ndim = x$num, .mute = x$options$.mute)
}

I know that this isn't reproducible but it otherwise works when using Isomap directly instead of embed(,"Isomap"). I've tried importing dimRedMethodList too but had the same error. Loading the package prior to invoking this function also works.

gdkrmr commented 7 years ago

That is very strange, I export dimRedMethodList just as any other function and it isn't even a method.

From your error message I would think that this is unrelated, but try running:

names(completeClassDefinition("dimRedMethod", doExtends = FALSE)@subclasses)

from inside your package. You might need to import the classes dimRedMethod and all children (or maybe just the methods you are using) separately.

Have you tried calling dimRed::embed(...)?

topepo commented 7 years ago

I added a print statement for that line and get output before the error:

 [1] "DiffusionMaps"       "DRR"                 "FastICA"             "KamadaKawai"        
 [5] "DrL"                 "FruchtermanReingold" "HLLE"                "Isomap"             
 [9] "kPCA"                "LaplacianEigenmaps"  "LLE"                 "MDS"                
[13] "nMDS"                "PCA"                 "tSNE"               
Error in eval(expr, envir, enclos) : 
  could not find function "dimRedMethodList"

Calling as dimRed::embed had the same results.

It is weird... before loading dimRed I can access it via dimRed::dimRedMethodList and dimRed:::dimRedMethodList. Even more, I imported the whole dimRed package and still get the same error.

I'll figure out how to convert over to non-embed code. Can .mute be passed into the @fun and @apply functions?

gdkrmr commented 7 years ago

that is strange, I will try this myself when I find some time. You can look at the implementation of the embed function and simply copy the code I use for muting: https://github.com/gdkrmr/dimRed/blob/master/R/embed.R#L115

You are trying to use Isomap? I had some problems with the CVST package I use for the DRR method and had to import the whole thing because of namespace issues.

Another weird namespace hack I had to do is here, maybe it helps : https://github.com/gdkrmr/dimRed/blob/master/R/kpca.R#L116

gdkrmr commented 7 years ago

I can reproduce it without a package:

  dimRed::embed(dimRed::dimRedData(iris[1:4]),
                "Isomap", knn = 25,
                ndim = 2, .mute = "")

in a fresh R session gives the same error.

gdkrmr commented 7 years ago

fixed with https://github.com/gdkrmr/dimRed/commit/36f497549c9ed0c6fd544967ca2eb4b43fd95b35

topepo commented 7 years ago

It works for me. Thanks