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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: case.match
> ### Title: Uses matching methods to select cases for qualitative analysis
> ### Aliases: case.match
> ### Keywords: ~case selection ~matching
> 
> ### ** Examples
> 
> 
> data(EU)
> mvars <- c("socialist","rgdpc","FHc","FHp","trade")
> dropvars <- c("countryname","population")
> 
> ## In this example, I subset to the first 40 obs. to cut run-time
> out <- case.match(data=EU[1:40,], id.var="countryname", leaveout.vars=dropvars,
+              distance="mahalanobis", case.N=2, 
+              number.of.matches.to.return=10,
+              treatment.var="eu", max.variance=TRUE)
[1] "Matching variables: rgdpc, trade, FHp, FHc, socialist, eu"
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
caseMatch
 --- call from context --- 
case.match(data = EU[1:40, ], id.var = "countryname", leaveout.vars = dropvars, 
    distance = "mahalanobis", case.N = 2, number.of.matches.to.return = 10, 
    treatment.var = "eu", max.variance = TRUE)
 --- call from argument --- 
if (f(covX) == F) {
    stop("Matching variables are too collinear to calculate the mahalanobis distance.  \n         Either retry with euclidean distance or a different combination of matching variables.")
}
 --- R stacktrace ---
where 1: case.match(data = EU[1:40, ], id.var = "countryname", leaveout.vars = dropvars, 
    distance = "mahalanobis", case.N = 2, number.of.matches.to.return = 10, 
    treatment.var = "eu", max.variance = TRUE)

 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context --- 
function (data, id.var, case.N = 2, distance = "mahalanobis", 
    design.type = "most similar", match.case = NULL, greedy.match = "pareto", 
    number.of.matches.to.return = 1, treatment.var = NULL, outcome.var = NULL, 
    leaveout.vars = NULL, max.variance = FALSE, max.variance.outcome = FALSE, 
    variance.tolerance = 0.1, max.spread = FALSE, max.spread.outcome = FALSE, 
    varweights = NULL) 
{
    if (case.N < 2) {
        stop("case.N must be an integer 2 or larger", call. = FALSE)
    }
    if (length(match.case) > 1) {
        stop("match.case should be a string vector length = 1", 
            call. = FALSE)
    }
    if (length(treatment.var) > 1) {
        stop("Only one treatment variable can be specified.")
    }
    if (max(names(data) == treatment.var, na.omit = T) == F) {
        stop("Treatment variable is missing from the dataset.")
    }
    if (class(leaveout.vars) == "character") {
        for (i in 1:length(leaveout.vars)) {
            if (max(names(data) == leaveout.vars[i], na.omit = T) == 
                F) {
                stop("At least 1 leaveout.vars variable is missing from the dataset.")
            }
        }
    }
    if (max.variance == T & max.spread == T) {
        stop("Cannot specify max.variance==TRUE & max.spread==TRUE.  Pick one or the other.")
    }
    if (length(outcome.var) > 1) {
        stop("Only one outcome variable can be specified.")
    }
    if (max(names(data) == outcome.var, na.omit = T) == F) {
        stop("Outcome variable is missing from the dataset.")
    }
    if (max.variance.outcome == T & max.spread.outcome == T) {
        stop("Cannot specify max.variance.outcome==TRUE & max.spread.outcome==TRUE.  Pick one or the other.")
    }
    if (is.null(treatment.var) == T & max.variance == T) {
        stop("Cannot specify max.variance==TRUE without specifying treatment variable")
    }
    if (is.null(treatment.var) == T & max.spread == T) {
        stop("Cannot specify max.spread==TRUE without specifying treatment variable")
    }
    if (is.null(outcome.var) == T & max.variance.outcome == T) {
        stop("Cannot specify max.variance.outcome==TRUE without specifying outcome variable")
    }
    if (is.null(outcome.var) == T & max.spread.outcome == T) {
        stop("Cannot specify max.spread.outcome==TRUE without specifying outcome variable")
    }
    if (design.type != "most similar" & design.type != "most different") {
        stop("Design type is not correctly specified")
    }
    if (class(leaveout.vars) == "numeric") {
        leaveout <- leaveout.vars
    }
    if (class(leaveout.vars) == "character") {
        leaveout <- charmatch(leaveout.vars, names(data))
    }
    if (is.null(leaveout.vars) == F) {
        print(paste0("Matching variables: ", paste(names(data[, 
            -c(leaveout), drop = F]), collapse = ", ")))
    }
    else {
        print(paste0("Matching variables: ", paste(names(data), 
            collapse = ", ")))
    }
    if (is.null(leaveout.vars) == F) {
        if (ifelse(sum(as.numeric(is.na(data[, -c(leaveout), 
            drop = F]))) > 0, TRUE, FALSE) == TRUE) {
            print("Some observations are missing data on the specified variables.  These observations have been removed.")
        }
        missing <- as.vector(row.names(na.omit(data[, -c(leaveout), 
            drop = F])))
        data <- data[which(rownames(data) %in% missing), , drop = F]
    }
    else {
        if (ifelse(sum(as.numeric(is.na(data))) > 0, TRUE, FALSE) == 
            TRUE) {
            print("Some observations are missing data on the specified variables.  These observations have been removed.")
        }
        missing <- as.vector(row.names(na.omit(data)))
        data <- data[which(rownames(data) %in% missing), , drop = F]
    }
    unit.names <- as.vector(data[, which(names(data) == id.var)])
    if (is.null(leaveout.vars) == T & is.null(treatment.var) == 
        T & is.null(outcome.var) == T) {
        X <- data[, -which(names(data) == id.var), drop = F]
    }
    if (is.null(leaveout.vars) == F & is.null(treatment.var) == 
        T & is.null(outcome.var) == T) {
        X <- data[, -c(which(names(data) == id.var), leaveout), 
            drop = F]
    }
    if (is.null(leaveout.vars) == F & is.null(treatment.var) == 
        F & is.null(outcome.var) == T) {
        X <- data[, -c(which(names(data) == id.var), leaveout, 
            which(names(data) == treatment.var)), drop = F]
        treat <- data[, which(names(data) == treatment.var)]
    }
    if (is.null(leaveout.vars) == T & is.null(treatment.var) == 
        F & is.null(outcome.var) == T) {
        X <- data[, -c(which(names(data) == id.var), which(names(data) == 
            treatment.var)), drop = F]
        treat <- data[, which(names(data) == treatment.var)]
    }
    if (is.null(leaveout.vars) == T & is.null(treatment.var) == 
        T & is.null(outcome.var) == F) {
        X <- data[, -c(which(names(data) == id.var), which(names(data) == 
            outcome.var)), drop = F]
        outcome <- data[, which(names(data) == outcome.var)]
    }
    if (is.null(leaveout.vars) == T & is.null(treatment.var) == 
        F & is.null(outcome.var) == F) {
        X <- data[, -c(which(names(data) == id.var), which(names(data) == 
            treatment.var), which(names(data) == outcome.var)), 
            drop = F]
        treat <- data[, which(names(data) == treatment.var)]
        outcome <- data[, which(names(data) == outcome.var)]
    }
    if (is.null(leaveout.vars) == F & is.null(treatment.var) == 
        T & is.null(outcome.var) == F) {
        X <- data[, -c(which(names(data) == id.var), leaveout, 
            which(names(data) == outcome.var)), drop = F]
        outcome <- data[, which(names(data) == outcome.var)]
    }
    if (is.null(leaveout.vars) == F & is.null(treatment.var) == 
        F & is.null(outcome.var) == F) {
        X <- data[, -c(which(names(data) == id.var), leaveout, 
            which(names(data) == treatment.var), which(names(data) == 
                outcome.var)), drop = F]
        treat <- data[, which(names(data) == treatment.var)]
        outcome <- data[, which(names(data) == outcome.var)]
    }
    if (!is.null(varweights)) {
        if (length(varweights) != ncol(X)) {
            stop("Number of variable weights does not match number of variables.")
        }
    }
    if (!is.null(varweights)) {
        if (!is.null(names(varweights))) {
            if (sum(names(varweights) != colnames(X)) > 0) {
                stop("Names of variable weights do not match names of variables.")
            }
        }
    }
    N <- nrow(data)
    id <- seq(1, N, 1)
    if (distance == "mahalanobis") {
        covX <- cov(X)
    }
    if (distance == "euclidean") {
        covX <- diag(ncol(X))
    }
    if (distance == "standardized") {
        stddev <- apply(X, MARGIN = 2, FUN = sd)
        X <- as.data.frame(t(apply(X, MARGIN = 1, FUN = function(x) {
            x/stddev
        })))
        covX <- diag(ncol(X))
    }
    if (exists("covX") == F) {
        stop("Matching distance not specified properly. Check spelling")
    }
    f <- function(m) class(try(solve(m), silent = T)) == "matrix"
    if (f(covX) == F) {
        stop("Matching variables are too collinear to calculate the mahalanobis distance.  \n         Either retry with euclidean distance or a different combination of matching variables.")
    }
    if (is.null(match.case) == T) {
        print(paste("There are", N, "choose", case.N, "=", choose(N, 
            case.N), "possible case combinations"))
    }
    if (is.null(match.case) == F) {
        print(paste("There are", (N - 1), "choose", (case.N - 
            1), "=", choose((N - 1), (case.N - 1)), "possible case combinations"))
    }
    if (is.null(match.case) == F) {
        if (length(grep(match.case, unit.names, fixed = T)) == 
            0) {
            stop("match.case does not match any of the unit IDs", 
                call. = FALSE)
        }
        match.case.id <- id[unit.names == match.case]
        if (length(match.case.id) > 1) {
            stop("match.case matches more than one unit ID", 
                call. = FALSE)
        }
        id2 <- rep(NA, length(id))
        id2[id == match.case.id] <- 1
        id2[id != match.case.id] <- seq(2, N, 1)
        id <- id2
        match.case.id <- 1
        X <- X[order(id), , drop = F]
        unit.names <- unit.names[order(id)]
        if (is.null(treatment.var) == F) {
            treat <- treat[order(id)]
        }
        if (is.null(outcome.var) == F) {
            outcome <- outcome[order(id)]
        }
        id <- sort(id)
        if (is.null(treatment.var) == T & is.null(outcome.var) == 
            T) {
            combin <- t(combn(id[-match.case.id], (case.N - 1)))
            combinations <- cbind(rep(match.case.id, nrow(combin)), 
                combin)
        }
        if (is.null(treatment.var) == F) {
            print("Matching only on units that have a different treatment value")
            treat.value <- treat[id == match.case.id]
            combin <- t(combn(id[-unique(c(match.case.id, which(treat == 
                treat.value)))], (case.N - 1)))
            combinations <- cbind(rep(match.case.id, nrow(combin)), 
                combin)
        }
        if (is.null(outcome.var) == F) {
            print("Matching only on units that have a different outcome value")
            outcome.value <- outcome[id == match.case.id]
            combin <- t(combn(id[-unique(c(match.case.id, which(outcome == 
                outcome.value)))], (case.N - 1)))
            combinations <- cbind(rep(match.case.id, nrow(combin)), 
                combin)
        }
    }
    if (is.null(match.case) == T) {
        combinations <- t(combn(id, case.N))
    }
    holder <- matrix(NA, nrow(X), nrow(X))
    if (is.null(varweights)) {
        varweights <- rep(1, ncol(X))
    }
    W <- diag(varweights)
    invCovW <- W %*% solve(covX) %*% W
    rownames(invCovW) <- colnames(invCovW) <- names(X)
    myMH <- function(Tnms, Cnms, inv.cov, data) {
        stopifnot(!is.null(dimnames(inv.cov)[[1]]), all.equal(dimnames(inv.cov)[[1]], 
            dimnames(inv.cov)[[2]]), all(dimnames(inv.cov)[[1]] %in% 
            names(data)))
        covars <- dimnames(inv.cov)[[1]]
        xdiffs <- as.matrix(data[Tnms, covars])
        xdiffs <- xdiffs - as.matrix(data[Cnms, covars])
        rowSums((xdiffs %*% inv.cov) * xdiffs)
    }
    if (is.null(match.case)) {
        holder <- outer(rownames(X), rownames(X), FUN = myMH, 
            inv.cov = invCovW, data = X)
    }
    else {
        holder <- outer(match.case.id, rownames(X), FUN = myMH, 
            inv.cov = invCovW, data = X)
        holder <- t(holder)
    }
    if (is.null(match.case) == T) {
        holder2 <- matrix(NA, nrow(combinations), (choose(case.N, 
            2)))
        pairings <- t(combn(case.N, 2))
        colnames(holder2) <- paste(pairings[, 1], "-", pairings[, 
            2], sep = "")
        for (k in 1:(choose(case.N, 2))) {
            for (i in 1:nrow(combinations)) {
                holder2[i, k] <- holder[combinations[i, pairings[k, 
                  2]], combinations[i, pairings[k, 1]]]
            }
        }
    }
    if (is.null(match.case) == F) {
        holder2 <- matrix(NA, nrow(combinations), (case.N - 1))
        pairings <- cbind(rep(1, length(seq(2, case.N, 1))), 
            seq(2, case.N, 1))
        colnames(holder2) <- paste(pairings[, 1], "-", pairings[, 
            2], sep = "")
        for (k in 1:ncol(holder2)) {
            for (i in 1:nrow(combinations)) {
                holder2[i, k] <- holder[combinations[i, pairings[k, 
                  2]], 1]
            }
        }
    }
    total.distance <- apply(holder2, MARGIN = 1, FUN = sum)
    distances <- data.frame(total.distance)
    for (i in 1:case.N) {
        distances <- cbind(distances, unit.names[combinations[, 
            i]])
    }
    distances.sort <- distances[order(distances[, 1]), ]
    colnames(distances.sort) <- c("distances", paste(rep("unit id", 
        case.N), 1:case.N))
    holder2.sort <- data.frame(holder2[order(distances[, 1]), 
        ])
    colnames(holder2.sort) <- paste(pairings[, 1], "-", pairings[, 
        2], sep = "")
    if (max.variance == TRUE) {
        variances <- rep(NA, nrow(distances.sort))
        for (i in 1:nrow(distances.sort)) {
            current.row <- distances.sort[i, ]
            units.matched <- unlist(apply(current.row, MARGIN = 2, 
                FUN = function(x) {
                  which(unit.names == x)
                }))
            values.to.check.variance <- data[units.matched, colnames(data) == 
                treatment.var]
            variances[i] <- var(values.to.check.variance)
        }
    }
    if (max.variance == TRUE) {
        if (length(variances[which(variances == max(variances, 
            na.rm = T))]) > number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(variances == 
                max(variances, na.rm = T)), ]
            treat.variance <- variances[which(variances == max(variances, 
                na.rm = T))]
        }
        if (length(variances[which(variances == max(variances, 
            na.rm = T))]) < number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(variances >= 
                quantile(variances, probs = (1 - variance.tolerance), 
                  na.rm = TRUE)), ]
            treat.variance <- variances[which(variances >= quantile(variances, 
                probs = 1 - variance.tolerance, na.rm = TRUE))]
        }
        distances.sort <- cbind(distances.sort.trim, treat.variance)
    }
    if (max.spread == TRUE) {
        spreadem <- function(vec, overall.min = min(vec), overall.max = min(vec)) {
            vec <- sort(vec)
            spread.dist <- c()
            for (k in 1:(length(vec) - 1)) {
                spread.dist <- c(spread.dist, vec[k + 1] - vec[k])
            }
            return(sum(spread.dist))
        }
        spread <- rep(NA, nrow(distances.sort))
        for (i in 1:nrow(distances.sort)) {
            current.row <- distances.sort[i, ]
            units.matched <- unlist(apply(current.row, MARGIN = 2, 
                FUN = function(x) {
                  which(unit.names == x)
                }))
            values.to.check.spread <- sort(data[units.matched, 
                colnames(data) == treatment.var])
            spread[i] <- spreadem(values.to.check.spread)
        }
    }
    if (max.spread == TRUE) {
        if (length(spread[which(spread == max(spread, na.rm = T))]) > 
            number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(spread == 
                max(spread, na.rm = T)), ]
            treat.spread <- spread[which(spread == max(spread, 
                na.rm = T))]
        }
        if (length(spread[which(spread == max(spread, na.rm = T))]) < 
            number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(spread >= 
                quantile(spread, probs = (1 - variance.tolerance), 
                  na.rm = TRUE)), ]
            treat.spread <- spread[which(spread >= quantile(spread, 
                probs = (1 - variance.tolerance), na.rm = TRUE))]
        }
        distances.sort <- cbind(distances.sort.trim, treat.spread)
    }
    if (max.variance.outcome == TRUE) {
        variances <- rep(NA, nrow(distances.sort))
        for (i in 1:nrow(distances.sort)) {
            current.row <- distances.sort[i, ]
            units.matched <- unlist(apply(current.row, MARGIN = 2, 
                FUN = function(x) {
                  which(unit.names == x)
                }))
            values.to.check.variance <- data[units.matched, colnames(data) == 
                outcome.var]
            variances[i] <- var(values.to.check.variance)
        }
    }
    if (max.variance.outcome == TRUE) {
        if (length(variances[which(variances == max(variances, 
            na.rm = T))]) > number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(variances == 
                max(variances, na.rm = T)), ]
            outcome.variance <- variances[which(variances == 
                max(variances, na.rm = T))]
        }
        if (length(variances[which(variances == max(variances, 
            na.rm = T))]) < number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(variances >= 
                quantile(variances, probs = (1 - variance.tolerance), 
                  na.rm = TRUE)), ]
            outcome.variance <- variances[which(variances >= 
                quantile(variances, probs = 1 - variance.tolerance, 
                  na.rm = TRUE))]
        }
        distances.sort <- cbind(distances.sort.trim, outcome.variance)
    }
    if (max.spread.outcome == TRUE) {
        spreadem <- function(vec, overall.min = min(vec), overall.max = min(vec)) {
            vec <- sort(vec)
            spread.dist <- c()
            for (k in 1:(length(vec) - 1)) {
                spread.dist <- c(spread.dist, vec[k + 1] - vec[k])
            }
            return(sum(spread.dist))
        }
        spread <- rep(NA, nrow(distances.sort))
        for (i in 1:nrow(distances.sort)) {
            current.row <- distances.sort[i, ]
            units.matched <- unlist(apply(current.row, MARGIN = 2, 
                FUN = function(x) {
                  which(unit.names == x)
                }))
            values.to.check.spread <- sort(data[units.matched, 
                colnames(data) == outcome.var])
            spread[i] <- spreadem(values.to.check.spread)
        }
    }
    if (max.spread.outcome == TRUE) {
        if (length(spread[which(spread == max(spread, na.rm = T))]) > 
            number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(spread == 
                max(spread, na.rm = T)), ]
            outcome.spread <- spread[which(spread == max(spread, 
                na.rm = T))]
        }
        if (length(spread[which(spread == max(spread, na.rm = T))]) < 
            number.of.matches.to.return) {
            distances.sort.trim <- distances.sort[which(spread >= 
                quantile(spread, probs = (1 - variance.tolerance), 
                  na.rm = TRUE)), ]
            outcome.spread <- spread[which(spread >= quantile(spread, 
                probs = (1 - variance.tolerance), na.rm = TRUE))]
        }
        distances.sort <- cbind(distances.sort.trim, outcome.spread)
    }
    if (greedy.match == "pareto" & design.type == "most similar" & 
        is.null(match.case) == T & case.N < 3) {
        sub_matches <- c()
        for (i in 1:length(data[, which(names(data) == id.var)])) {
            sub_matches[i] = min(distances.sort[distances.sort[, 
                c(2)] == data[, which(names(data) == id.var)][i] | 
                distances.sort[, c(3)] == data[, which(names(data) == 
                  id.var)][i], 1])
        }
        is.na(sub_matches) <- do.call(cbind, lapply(sub_matches, 
            is.infinite))
        sub_matches <- na.omit(sub_matches)
        sub_matches <- sort(unique(sub_matches))
        test_final = distances.sort[distances.sort[, 1] %in% 
            sub_matches, ]
        if (nrow(test_final) > number.of.matches.to.return) {
            distances.sort = test_final
        }
        if (nrow(test_final) < number.of.matches.to.return) {
            print("For more matches, change greedy.match to 'all'")
            distances.sort <- na.omit(test_final)
        }
    }
    if (greedy.match == "pareto" & design.type == "most different" & 
        is.null(match.case) == T) {
        distances.sort2 <- distances.sort[order(-distances.sort[, 
            1]), ]
        sub_matches <- c()
        for (i in 1:length(data[, which(names(data) == id.var)])) {
            sub_matches[i] = max(distances.sort2[distances.sort2[, 
                c(2)] == data[, which(names(data) == id.var)][i] | 
                distances.sort2[, c(3)] == data[, which(names(data) == 
                  id.var)][i], 1])
        }
        is.na(sub_matches) <- do.call(cbind, lapply(sub_matches, 
            is.infinite))
        sub_matches <- na.omit(sub_matches)
        sub_matches <- sort(unique(sub_matches))
        test_final = distances.sort[distances.sort[, 1] %in% 
            sub_matches, ]
        if (nrow(test_final) > number.of.matches.to.return) {
            distances.sort = test_final
        }
        if (nrow(test_final) < number.of.matches.to.return) {
            print("For more matches, change greedy.match to 'all'")
            distances.sort <- test_final
        }
    }
    if (greedy.match == "greedy" & design.type == "most similar" & 
        is.null(match.case) == T) {
        distance.temp <- distances.sort[, c(2, 3)]
        m <- matrix(unlist(distance.temp), ncol = ncol(distance.temp))
        for (i in 1:length(data[, which(names(data) == id.var)])) {
            caserows = which(m == data[, which(names(data) == 
                id.var)][i], arr.ind = TRUE)
            caserows2 <- caserows[order(caserows[, 1])]
            row.keep = caserows2[-1]
            row.keep2 <- na.omit(row.keep)
            if (length(row.keep2) > 0) {
                m = m[-row.keep2, ]
            }
        }
        test_final2 = distances.sort[distances.sort[, 2] %in% 
            m[, 1], ]
        test_final3 <- test_final2[match(unique(test_final2[, 
            2]), test_final2[, 2]), ]
        if (nrow(test_final3) > number.of.matches.to.return) {
            distances.sort = test_final3
        }
        if (nrow(test_final3) < number.of.matches.to.return) {
            print("For more matches, change greedy.match to 'pareto' or 'all'")
            distances.sort <- na.omit(test_final3)
        }
    }
    if (greedy.match == "greedy" & design.type == "most different" & 
        is.null(match.case) == T) {
        distance.temp <- distances.sort[, c(2, 3)][order(-distances.sort[, 
            1]), ]
        distance.matrix <- matrix(unlist(distance.temp), ncol = ncol(distance.temp))
        for (i in 1:length(data[, which(names(data) == id.var)])) {
            caserows = which(distance.matrix == data[, which(names(data) == 
                id.var)][i], arr.ind = TRUE)
            caserows2 <- caserows[order(caserows[, 1])]
            row.keep = caserows2[-1]
            row.keep2 <- na.omit(row.keep)
            if (length(row.keep2) > 0) {
                distance.matrix = distance.matrix[-row.keep2, 
                  ]
            }
        }
        test_final2 = distances.sort[distances.sort[, 2] %in% 
            m[, 1], ]
        test_final2 <- test_final2[order(-test_final2[, 1]), 
            ]
        test_final3 <- test_final2[match(unique(test_final2[, 
            2]), test_final2[, 2]), ]
        test_final3 <- test_final3[order(test_final3[, 1]), ]
        if (nrow(test_final3) > number.of.matches.to.return) {
            distances.sort = test_final3
        }
        if (nrow(test_final3) < number.of.matches.to.return) {
            print("For more matches, change greedy.match to 'pareto' or 'all'")
            distances.sort <- test_final3
        }
    }
    if (greedy.match == "all") {
        distances.sort = distances.sort
    }
    if (design.type == "most similar") {
        matches <- distances.sort[1:number.of.matches.to.return, 
            ]
        rownames(matches) <- seq(1, number.of.matches.to.return, 
            1)
        if (case.N >= 3) {
            holder2.sort <- holder2.sort[which(rownames(holder2.sort) %in% 
                rownames(distances.sort)), ]
            match.dist <- holder2.sort[1:number.of.matches.to.return, 
                ]
        }
        else {
            match.dist <- data.frame(as.matrix(distances.sort[1:number.of.matches.to.return, 
                1]))
            colnames(match.dist) <- colnames(holder2.sort)
        }
        match.units <- matches[, -1]
        case.distances <- c()
        for (i in 1:nrow(match.dist)) {
            case.distances[[i]] <- data.frame(match.dist[i, ])
            colnames(case.distances[[i]]) <- paste(as.matrix(match.units[i, 
                pairings[, 1]]), "-", as.matrix(match.units[i, 
                pairings[, 2]]), sep = "")
        }
        print(head(matches[1:number.of.matches.to.return, 1:as.numeric(case.N + 
            1)]))
        return(list(cases = matches, case.distances = case.distances))
    }
    if (design.type == "most different") {
        if (number.of.matches.to.return > nrow(distances.sort)) {
            print("To produce more matches, change the matching specification")
            number.of.matches.to.return = nrow(distances.sort)
        }
        matches <- distances.sort[nrow(distances.sort):(nrow(distances.sort) - 
            number.of.matches.to.return + 1), ]
        rownames(matches) <- rev(seq((nrow(distances.sort) - 
            number.of.matches.to.return + 1), nrow(distances.sort), 
            1))
        if (case.N >= 3) {
            holder2.sort <- holder2.sort[which(rownames(holder2.sort) %in% 
                rownames(distances.sort)), ]
            match.dist <- holder2.sort[nrow(distances.sort):(nrow(distances.sort) - 
                number.of.matches.to.return + 1), ]
        }
        else {
            match.dist <- data.frame(as.matrix(distances.sort[nrow(distances.sort):(nrow(distances.sort) - 
                number.of.matches.to.return + 1), 1]))
            colnames(match.dist) <- colnames(holder2.sort)
        }
        match.units <- matches[, -1]
        case.distances <- c()
        for (i in 1:nrow(match.dist)) {
            case.distances[[i]] <- data.frame(match.dist[i, ])
            colnames(case.distances[[i]]) <- paste(as.matrix(match.units[i, 
                pairings[, 1]]), "-", as.matrix(match.units[i, 
                pairings[, 2]]), sep = "")
        }
        print(head(matches[1:number.of.matches.to.return, 1:as.numeric(case.N + 
            1)]))
        return(list(cases = matches, case.distances = case.distances))
    }
}
<bytecode: 0x55fd969e4dd8>
<environment: namespace:caseMatch>
 --- function search by body ---
Function case.match in namespace caseMatch has this body.
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1