Leong Wun Meng Leong Wun Meng - 1 month ago 15
R Question

Error in knearest(Darr, P_set, K) : object 'knD' not found

i used Package ‘smotefamily’ in R
then i used example in the CRDN doc

data_example = sample_generator(10000,ratio = 0.80)
genData = ADAS(data_example[,-3],data_example[,3])
genData_2 = ADAS(data_example[,-3],data_example[,3],K=7)


but there have a error

Error in knearest(Darr, P_set, C) : object 'knD' not found


I just want to use ADAS .
this is the document link:
document

Answer

Tracing this error, it's thrown from knearest whose source is:

> knearest
function (D, P, n_clust) 
{
    if (requireNamespace("FNN", quietly = TRUE)) {
        knD <- FNN::knnx.index(D, P, k = (n_clust + 1), algo = "kd_tree")
    }
    knD = knD * (knD != row(knD))
    que = which(knD[, 1] > 0)
    for (i in que) {
        knD[i, which(knD[i, ] == 0)] = knD[i, 1]
        knD[i, 1] = 0
    }
    return(knD[, 2:(n_clust + 1)])
}

The if statement in this function has no else for when requireNamespace returns FALSE and the FNN dependency is only in 'Suggests' in the package metadata so isn't automatically installed. To get the example to run first install FNN:

install.packages("FNN")
Comments