Running examples in ‘ssc-Ex.R’ failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: setred
> ### Title: SETRED method
> ### Aliases: setred
> 
> ### ** Examples
> 
> 
> library(ssc)
> 
> ## Load Wine data set
> data(wine)
> 
> cls <- which(colnames(wine) == "Wine")
> x <- wine[, -cls] # instances without classes
> y <- wine[, cls] # the classes
> x <- scale(x) # scale the attributes
> 
> ## Prepare data
> set.seed(20)
> # Use 50% of instances for training
> tra.idx <- sample(x = length(y), size = ceiling(length(y) * 0.5))
> xtrain <- x[tra.idx,] # training instances
> ytrain <- y[tra.idx]  # classes of training instances
> # Use 70% of train instances as unlabeled set
> tra.na.idx <- sample(x = length(tra.idx), size = ceiling(length(tra.idx) * 0.7))
> ytrain[tra.na.idx] <- NA # remove class information of unlabeled instances
> 
> # Use the other 50% of instances for inductive testing
> tst.idx <- setdiff(1:length(y), tra.idx)
> xitest <- x[tst.idx,] # testing instances
> yitest <- y[tst.idx] # classes of testing instances
> 
> ## Example: Training from a set of instances with 1-NN as base classifier.
> m1 <- setred(x = xtrain, y = ytrain, dist = "euclidean", 
+             learner = caret::knn3, 
+             learner.pars = list(k = 1),
+             pred = "predict")
> pred1 <- predict(m1, xitest)
> table(pred1, yitest)
     yitest
pred1  1  2  3
    1 29  4  0
    2  0 29  2
    3  0  1 24
> 
> ## Example: Training from a distance matrix with 1-NN as base classifier.
> # Compute distances between training instances
> library(proxy)

Attaching package: ‘proxy’

The following objects are masked from ‘package:stats’:

    as.dist, dist

The following object is masked from ‘package:base’:

    as.matrix

> D <- dist(x = xtrain, method = "euclidean", by_rows = TRUE)
> 
> m2 <- setred(x = D, y = ytrain, x.inst = FALSE,
+             learner = ssc::oneNN, 
+             pred = "predict",
+             pred.pars = list(distance.weighting = "none"))
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
ssc
 --- call from context --- 
setredG(y, x, gen.learner1, gen.pred1, theta, max.iter, perc.full)
 --- call from argument --- 
if (class(D) == "dist") {
    D <- proxy::as.matrix(D)
}
 --- R stacktrace ---
where 1: setredG(y, x, gen.learner1, gen.pred1, theta, max.iter, perc.full)
where 2: setred(x = D, y = ytrain, x.inst = FALSE, learner = ssc::oneNN, 
    pred = "predict", pred.pars = list(distance.weighting = "none"))

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (y, D, gen.learner, gen.pred, theta = 0.1, max.iter = 50, 
    perc.full = 0.7) 
{
    if (!is.factor(y)) {
        if (!is.vector(y)) {
            stop("Parameter y is neither a vector nor a factor.")
        }
        else {
            y = as.factor(y)
        }
    }
    if (class(D) == "dist") {
        D <- proxy::as.matrix(D)
    }
    if (!is.matrix(D)) {
        stop("Parameter D is neither a matrix or a dist object.")
    }
    else if (nrow(D) != ncol(D)) {
        stop("The distance matrix D is not a square matrix.")
    }
    else if (nrow(D) != length(y)) {
        stop(sprintf(paste("The dimensions of the matrix D is %i x %i", 
            "and it's expected %i x %i according to the size of y."), 
            nrow(D), ncol(D), length(y), length(y)))
    }
    if (!(theta >= 0 && theta <= 1)) {
        stop("theta must be between 0 and 1")
    }
    if (max.iter < 1) {
        stop("Parameter max.iter is less than 1. Expected a value greater than and equal to 1.")
    }
    if (perc.full < 0 || perc.full > 1) {
        stop("Parameter perc.full is not in the range 0 to 1.")
    }
    classes <- levels(y)
    nclasses <- length(classes)
    ynew <- y
    labeled <- which(!is.na(y))
    unlabeled <- which(is.na(y))
    if (length(labeled) == 0) {
        stop("The labeled set is empty. All the values in y parameter are NA.")
    }
    if (length(unlabeled) == 0) {
        stop("The unlabeled set is empty. None value in y parameter is NA.")
    }
    cls.summary <- summary(y[labeled])
    proportion <- cls.summary/length(labeled)
    cantClass <- round(cls.summary/min(cls.summary))
    totalPerIter <- sum(cantClass)
    count.full <- length(labeled) + round(length(unlabeled) * 
        perc.full)
    iter <- 1
    while ((length(labeled) < count.full) && (length(unlabeled) >= 
        totalPerIter) && (iter <= max.iter)) {
        model <- gen.learner(labeled, ynew[labeled])
        prob <- checkProb(prob = gen.pred(model, unlabeled), 
            ninstances = length(unlabeled), classes)
        selection <- selectInstances(cantClass, prob)
        nlabeled.old <- length(labeled)
        labeled.prime <- unlabeled[selection$unlabeled.idx]
        sel.classes <- classes[selection$class.idx]
        ynew[labeled.prime] <- sel.classes
        labeled <- c(labeled, labeled.prime)
        unlabeled <- unlabeled[-selection$unlabeled.idx]
        nlabeled.new <- length(labeled)
        ady <- vector("list", nlabeled.new)
        for (i in (nlabeled.old + 1):nlabeled.new) {
            for (j in 1:(i - 1)) {
                con <- TRUE
                for (k in 1:nlabeled.new) if (k != i && k != 
                  j && D[labeled[i], labeled[j]] > max(D[labeled[i], 
                  labeled[k]], D[labeled[k], labeled[j]])) {
                  con <- FALSE
                  break
                }
                if (con) {
                  ady[[i]] <- c(ady[[i]], j)
                  ady[[j]] <- c(ady[[j]], i)
                }
            }
        }
        noise.insts <- c()
        for (i in (nlabeled.old + 1):nlabeled.new) {
            propi <- proportion[unclass(ynew[labeled[i]])]
            Oi <- 0
            nv <- W <- k <- 0
            for (j in ady[[i]]) {
                k <- k + 1
                W[k] <- 1/(1 + D[labeled[i], labeled[j]])
                if (ynew[labeled[i]] != ynew[labeled[j]]) {
                  Oi <- Oi + W[k]
                  nv <- nv + 1
                }
            }
            if (normalCriterion(theta, Oi, length(ady[[i]]), 
                propi, W)) {
                noise.insts <- c(noise.insts, i)
            }
        }
        if (length(noise.insts) > 0) {
            ynew[labeled[noise.insts]] <- NA
            labeled <- labeled[-noise.insts]
        }
        iter <- iter + 1
    }
    model <- gen.learner(labeled, ynew[labeled])
    result <- list(model = model, instances.index = labeled)
    class(result) <- "setredG"
    result
}
<bytecode: 0x55c2317a8770>
<environment: namespace:ssc>
 --- function search by body ---
Function setredG in namespace ssc has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1