Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
since data.table uses reference semantics rather
than lazy data structures, it is necessary to
use the force() to make sure the parameters
dist_var and variable are evaluated before the
object data is manipulated in the function body
of kNN.

If the return value does not have the correct
type (R/kNNFaster#185), then indexing does
not behave as expected in one of the tests
(tests/test_kNN.R#65)
  • Loading branch information
GregorDeCillia committed Apr 17, 2020
1 parent c7ace79 commit f32375b
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/kNNFaster.R
Expand Up @@ -114,6 +114,8 @@ kNN <- function(data, variable=colnames(data), metric=NULL, k=5, dist_var=colnam
makeNA=NULL,NAcond=NULL, impNA=TRUE, donorcond=NULL,mixed=vector(),mixed.constant=NULL,trace=FALSE,
imp_var=TRUE,imp_suffix="imp", addRF=FALSE, onlyRF=FALSE,addRandom=FALSE,useImputedDist=TRUE,weightDist=FALSE) {
data_df <- !is.data.table(data)
force(variable)
force(dist_var)
if (data_df) {
data <- as.data.table(data)
} else {
Expand Down Expand Up @@ -180,6 +182,8 @@ kNN <- function(data, variable=colnames(data), metric=NULL, k=5, dist_var=colnam
}
if(length(variable)==0){
warning(paste("Nothing is imputed, because all variables to be imputed only contains missings."))
if (data_df)
data <- as.data.frame(data)
return(data)
}
orders <- data[,sapply(.SD,is.ordered)]
Expand Down

0 comments on commit f32375b

Please sign in to comment.