kknn icon indicating copy to clipboard operation
kknn copied to clipboard

running when imported

Open topepo opened this issue 6 years ago • 1 comments

When kknn is referenced by namespace (as opposed to being fully attached via library) an error occurs:

train.con <- 
  kknn::train.kknn(
    Sepal.Width ~ ., 
    data = iris, 
    kmax = 6, 
    kernel = c("rectangular", "triangular", "epanechnikov",
               "gaussian", "rank", "optimal")
  )
#> Error in get(ctr, mode = "function", envir = parent.frame()): object 'contr.dummy' of mode 'function' was not found
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
 [1] compiler_3.5.0  magrittr_1.5    Matrix_1.2-14   tools_3.5.0     igraph_1.2.2    yaml_2.2.0      grid_3.5.0     
 [8] pkgconfig_2.0.2 kknn_1.3.2      lattice_0.20-35

Created on 2018-10-02 by the reprex package (v0.2.1)

(the kknn version was installed from GH)

Perhaps defining the argument to be

contrasts = c(unordered = "kknn::contr.dummy", ordered = "kknn::contr.ordinal")

or use getFromNamespace or getAnywhere to reference it would work.

We'd rather import the package when using it in another package to avoid name conflicts.

topepo avatar Oct 03 '18 01:10 topepo

I agree with this change. I'm using parsnip and kknn is failing because of

Error in get(ctr, mode = "function", envir = parent.frame()) : 
  object 'contr.dummy' of mode 'function' was not found

mdancho84 avatar May 24 '20 17:05 mdancho84