Running examples in 'telefit-Ex.R' failed
The error most likely occurred in:

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: eof
> ### Title: Performs an EOF decomposition of the data
> ### Aliases: eof
> 
> ### ** Examples
> 
> data("coprecip")
> attach(coprecip)
> 
> # compute ocean surface temperature eofs
> eofs = eof(Z)
> 
> # view first EOF, which corresponds to the El-Nino pattern
> coords.r.mod = coords.r
> coords.r.mod[,1][coords.r.mod[,1]>0] =
+   coords.r.mod[,1][coords.r.mod[,1]>0] - 360
> fields::quilt.plot(coords.r.mod, eofs$patterns[,1])
> 
> # alternatively, the plot.stData function can directly compute and plot EOFs
> plot(coprecip, type='eof', pattern=1)
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
telefit
 --- call from context --- 
plot.stData(coprecip, type = "eof", pattern = 1)
 --- call from argument --- 
if (class(stData$Y) != "matrix") stData$Y = matrix(stData$Y, 
    nrow = nrow(stData$coords.s))
 --- R stacktrace ---
where 1: plot.stData(coprecip, type = "eof", pattern = 1)
where 2: plot(coprecip, type = "eof", pattern = 1)

 --- value of length: 2 type: logical ---
[1] FALSE  TRUE
 --- function from context --- 
function (x, type = "response", t = NULL, p = NULL, map = "world", 
    region = ".", coord.s = NULL, coord.r = NULL, zlim = NULL, 
    fill.lab = NULL, lab.teleconnection = expression(alpha), 
    fill.lab.width = 20, category.breaks = NULL, coords.knots = NULL, 
    signif.telecon = F, dots = NULL, pattern = 1, lwd = 1.75, 
    cutoff = 0.9, signif.level = 0.05, alpha = 0.2, zmid = 0, 
    contour = c(F, F), ...) 
{
    stData = x
    dots = c(dots, list(...))
    dots = dots[!duplicated(dots)]
    for (x in setdiff(names(formals(eval(match.call()[[1]]))), 
        c("dots", "..."))) {
        if (x %in% names(dots)) {
            assign(eval(x), dots[[x]])
        }
    }
    if (!is.null(coord.s)) 
        coord.s = unlist(coord.s)
    if (is.null(t)) 
        t = stData$tLabs[1]
    if (is.null(p)) 
        p = 2
    if (!is.null(stData$Y)) {
        if (class(stData$Y) != "matrix") 
            stData$Y = matrix(stData$Y, nrow = nrow(stData$coords.s))
    }
    if (!is.null(stData$Y.cat)) {
        if (class(stData$Y.cat) != "matrix") 
            stData$Y.cat = matrix(stData$Y.cat, nrow = nrow(stData$coords.s))
    }
    if (!is.null(coords.knots)) {
        coords.knots = data.frame(coords.knots)
        colnames(coords.knots) = c("lon", "lat")
        coords.knots = rbind(coords.knots, coords.knots %>% mutate(lon = lon - 
            360))
    }
    ret = NULL
    match.opts = c("response", "covariate", "remote", "teleconnection", 
        "eof", "eof_scores", "cat.response", "teleconnection_knot", 
        "teleconnection_knot_local", "eof_scree", "eof_cor", 
        "local_cor", "sd.response", "remote_cor")
    type = match.opts[pmatch(type, match.opts)]
    if (type == "response") {
        Y = data.frame(Y = stData$Y[, match(t, stData$tLabs)], 
            lon.Y = stData$coords.s[, 1], lat.Y = stData$coords.s[, 
                2])
        if (signif.telecon) {
            Y = cbind(Y, signif = attr(stData$Y, "signif")[, 
                match(t, stData$tLabs)])
        }
        lab.col = ifelse(is.null(fill.lab), stData$Y.lab, fill.lab)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "sd.response") {
        Y = data.frame(Y = apply(stData$Y, 1, sd), lon.Y = stData$coords.s[, 
            1], lat.Y = stData$coords.s[, 2])
        lab.col = ifelse(is.null(fill.lab), paste("S.D.", stData$Y.lab), 
            fill.lab)
        t = "Response S.D."
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "covariate") {
        Y = data.frame(Y = stData$X[, p, match(t, stData$tLabs)], 
            lon.Y = stData$coords.s[, 1], lat.Y = stData$coords.s[, 
                2])
        lab.col = ifelse(is.null(fill.lab), stData$X.lab, fill.lab)
        scheme.col = list(low = "#008837", mid = "#f7f7f7", high = "#7b3294")
    }
    else if (type == "remote") {
        Y = data.frame(Y = stData$Z[, match(t, stData$tLabs)], 
            lon.Y = stData$coords.r[, 1], lat.Y = stData$coords.r[, 
                2])
        lab.col = ifelse(is.null(fill.lab), stData$Z.lab, fill.lab)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "teleconnection") {
        n = nrow(stData$coords.s)
        r = nrow(stData$coords.r)
        if (is.null(coord.s)) 
            coord.s = stData$coords.s[round(n/2), ]
        coord.s.ind = which.min(rdist.earth(matrix(coord.s, ncol = 2), 
            stData$coords.s))
        coord.s = stData$coords.s[coord.s.ind, ]
        Y = data.frame(Y = as.numeric(stData$alpha), signif = stData$alpha_signif, 
            lon.Z = stData$coords.r[, 1], lat.Z = stData$coords.r[, 
                2], lon.Y = rep(stData$coords.s[, 1], rep(r, 
                n)), lat.Y = rep(stData$coords.s[, 2], rep(r, 
                n))) %>% filter(lon.Y == coord.s[1], lat.Y == 
            coord.s[2]) %>% mutate(lon.Y = lon.Z, lat.Y = lat.Z)
        lab.col = ifelse(is.null(fill.lab), lab.teleconnection, 
            fill.lab)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "teleconnection_knot") {
        n = nrow(stData$coords.s)
        r_knots = nrow(stData$coords.knots)
        if (is.null(coord.s)) 
            coord.s = stData$coords.s[round(n/2), ]
        coord.s.ind = which.min(rdist.earth(matrix(coord.s, ncol = 2), 
            stData$coords.s))
        coord.s = stData$coords.s[coord.s.ind, ]
        Y = data.frame(Y = stData$alpha_knots, signif = ifelse(stData$alpha_knots_signif, 
            3, 0), lon.Z = stData$coords.knots[, 1], lat.Z = stData$coords.knots[, 
            2], lon.Y = rep(stData$coords.s[, 1], rep(r_knots, 
            n)), lat.Y = rep(stData$coords.s[, 2], rep(r_knots, 
            n))) %>% filter(lon.Y == stData$coords.s[coord.s.ind, 
            1], lat.Y == stData$coords.s[coord.s.ind, 2]) %>% 
            mutate(lon.Y = lon.Z, lat.Y = lat.Z)
        lab.col = ifelse(is.null(fill.lab), lab.teleconnection, 
            fill.lab)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "teleconnection_knot_local") {
        n = nrow(stData$coords.s)
        r_knots = nrow(stData$coords.knots)
        if (is.null(coord.r)) 
            coord.r = stData$coords.s[round(r_knots/2), ]
        Y = data.frame(Y = stData$alpha_knots, lon.Z = stData$coords.knots[, 
            1], lat.Z = stData$coords.knots[, 2], lon.Y = rep(stData$coords.s[, 
            1], rep(r_knots, n)), lat.Y = rep(stData$coords.s[, 
            2], rep(r_knots, n))) %>% filter(lon.Z == coord.r[1], 
            lat.Z == coord.r[2])
        lab.col = ifelse(is.null(fill.lab), lab.teleconnection, 
            fill.lab)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "cat.response") {
        if (is.null(stData$Y.cat)) {
            stData$Y.cat = stData$Y
            for (s in 1:nrow(stData$Y)) {
                stData$Y.cat[s, ] = 1 + findInterval(stData$Y[s, 
                  ], category.breaks[s, ])
            }
        }
        if (ncol(category.breaks) == 1) {
            cat.labels = c("Below average", "Above average")
            scheme.col = c(`Below average` = "#fc8d59", `Above average` = "#91bfdb")
        }
        else if (ncol(category.breaks) == 2) {
            cat.labels = c("Below average", "Near average", "Above average")
            scheme.col = c(`Below average` = "#fc8d59", `Near average` = "#ffffbf", 
                `Above average` = "#91bfdb")
        }
        Y.cat = as.numeric(stData$Y.cat[, match(t, stData$tLabs)])
        Y.cat = factor(Y.cat, labels = cat.labels[sort(unique(Y.cat))])
        Y = data.frame(Y = Y.cat, lon.Y = stData$coords.s[, 1], 
            lat.Y = stData$coords.s[, 2])
        lab.col = ifelse(is.null(fill.lab), paste(stData$Y.lab, 
            "level"), fill.lab)
    }
    else if (type == "eof") {
        Y = data.frame(Y = eof(stData$Z)$patterns[, pattern], 
            lon.Y = stData$coords.r[, 1], lat.Y = stData$coords.r[, 
                2])
        lab.col = ifelse(is.null(fill.lab), "", fill.lab)
        t = paste("EOF", pattern)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "eof_scores") {
        ret = ggplot(melt(eof(stData$Z)$scores, varnames = c("t", 
            "EOF")) %>% filter(EOF %in% pattern) %>% mutate(EOF = factor(EOF), 
            t = as.numeric(stData$tLabs[t])), aes(x = t, y = value, 
            color = EOF)) + geom_line() + ylab("Score") + xlab("Year")
    }
    else if (type == "eof_scree") {
        e = eof(stData$Z)
        ret = cowplot::plot_grid(ggplot(data.frame(EOF = 1:length(e$sd), 
            sd = e$sd), aes(x = EOF, y = sd)) + geom_line() + 
            ylab("Standard deviation") + xlab("EOF") + ggtitle("EOF standard deviations"), 
            ggplot(data.frame(EOF = 1:length(e$sd), cum = cumsum(e$sd^2)/sum(e$sd^2)), 
                aes(x = EOF, y = cum)) + geom_line() + ylab("Proportion of variance") + 
                xlab("EOF") + ggtitle("EOF contributions") + 
                geom_hline(yintercept = cutoff, lty = 2), ncol = 2)
    }
    else if (type == "eof_cor") {
        sc = eof(stData$Z)$scores[, pattern]
        Y = data.frame(Y = as.numeric(cor(sc, t(stData$Y))), 
            lon.Y = stData$coords.s[, 1], lat.Y = stData$coords.s[, 
                2])
        if (signif.telecon) {
            Y$signif = apply(stData$Y, 1, function(y) {
                cor.test(y, sc)$p.value
            }) < signif.level
        }
        lab.col = ifelse(is.null(fill.lab), "Cor.", fill.lab)
        t = paste("Pointwise correlations with EOF", pattern)
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "local_cor") {
        Y = foreach(i = 1:nrow(stData$coords.s), .combine = "rbind") %do% 
            {
                r = data.frame(Y = cor(stData$Y[i, ], stData$X[i, 
                  p, ]), lon.Y = stData$coords.s[i, 1], lat.Y = stData$coords.s[i, 
                  2])
                if (signif.telecon) {
                  r$signif = cor.test(stData$Y[i, ], stData$X[i, 
                    p, ])$p.value < signif.level
                }
                r
            }
        lab.col = ifelse(is.null(fill.lab), "Cor.", fill.lab)
        t = paste("Pointwise correlations with", colnames(stData$X)[p])
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    else if (type == "remote_cor") {
        n = nrow(stData$coords.s)
        if (is.null(coord.s)) 
            coord.s = stData$coords.s[round(n/2), ]
        coord.s.ind = which.min(rdist.earth(matrix(coord.s, ncol = 2), 
            stData$coords.s))
        coord.s = stData$coords.s[coord.s.ind, ]
        Y = foreach(i = 1:nrow(stData$coords.r), .combine = "rbind") %do% 
            {
                r = data.frame(Y = cor(stData$Z[i, ], stData$Y[coord.s.ind, 
                  ]), lon.Y = stData$coords.r[i, 1], lat.Y = stData$coords.r[i, 
                  2])
                if (signif.telecon) {
                  r$signif = cor.test(stData$Z[i, ], stData$Y[coord.s.ind, 
                    ])$p.value < signif.level
                }
                r
            }
        lab.col = ifelse(is.null(fill.lab), "Cor.", fill.lab)
        t = paste("Pointwise correlations with", round(coord.s, 
            1))
        scheme.col = list(low = "#0571b0", mid = "#f7f7f7", high = "#ca0020")
    }
    if (!is.null(ret)) {
        return(ret)
    }
    if (type %in% c("remote", "teleconnection", "eof", "teleconnection_knot", 
        "remote_cor")) {
        if (max(Y$lon.Y) > 0) {
            if (min(Y$lon.Y) < 0) {
                lon.E = max(Y %>% filter(lon.Y <= 0) %>% dplyr::select(lon.Y))
                lon.W = min(Y %>% filter(lon.Y > 0) %>% dplyr::select(lon.Y)) - 
                  360
            }
            else {
                lon.E = max(Y$lon.Y) - 360
                lon.W = min(Y$lon.Y) - 360
            }
        }
        else {
            lon.E = max(Y$lon.Y)
            lon.W = min(Y$lon.Y)
        }
        lat.S = min(Y$lat.Y)
        lat.N = max(Y$lat.Y)
    }
    else {
        lon.W = min(Y$lon.Y)
        lon.E = max(Y$lon.Y)
        lat.S = min(Y$lat.Y)
        lat.N = max(Y$lat.Y)
    }
    world = map_data("state", region = region)
    if (map == "world") {
        world.raw = map_data("world") %>% filter(region != "USA")
        world.raw = rbind(world.raw, world.raw %>% mutate(long = long - 
            360, group = group + max(group) + 1))
        world = rbind(world, world.raw %>% mutate(group = group + 
            max(world$group) + 1))
    }
    if (type != "teleconnection_knot") {
        tile.aes = aes(x = lon.Y, y = lat.Y, fill = Y, z = Y)
        alpha = ifelse(signif.telecon, alpha, 1)
    }
    else {
        if (signif.telecon) {
            point.aes = aes(x = lon.Y, y = lat.Y, fill = Y, z = Y, 
                stroke = signif, color = ..level..)
        }
        else {
            point.aes = aes(x = lon.Y, y = lat.Y, fill = Y, z = Y, 
                stroke = 0, color = ..level..)
        }
    }
    if (class(lab.col) != "expression") {
        lab.col = str_wrap(lab.col, width = fill.lab.width)
    }
    if (type == "sd.response") {
        fillscale = scale_fill_distiller(lab.col, palette = "YlOrRd", 
            direction = 1)
    }
    else if (type == "cat.response") {
        fillscale = scale_fill_manual(lab.col, values = scheme.col)
    }
    else if (is.null(zlim)) {
        fillscale = scale_fill_gradient2(lab.col, low = scheme.col$low, 
            mid = scheme.col$mid, high = scheme.col$high, midpoint = zmid)
        colscale = scale_color_gradient2(lab.col, low = scheme.col$low, 
            mid = scheme.col$mid, high = scheme.col$high, midpoint = zmid)
    }
    else {
        fillscale = scale_fill_gradient2(lab.col, low = scheme.col$low, 
            mid = scheme.col$mid, high = scheme.col$high, limits = zlim, 
            midpoint = zmid)
        colscale = scale_color_gradient2(lab.col, low = scheme.col$low, 
            mid = scheme.col$mid, high = scheme.col$high, limits = zlim, 
            midpoint = zmid)
    }
    if (type != "teleconnection_knot") {
        worldmap = ggplot(world, aes(x = long, y = lat, group = group))
        if (contour[1]) {
            worldmap = worldmap + geom_contour(tile.aes, data = Y %>% 
                mutate(lon.Y = ifelse(lon.Y <= 0, lon.Y, lon.Y - 
                  360)), inherit.aes = F, alpha = alpha)
        }
        else {
            worldmap = worldmap + geom_raster(tile.aes, data = Y %>% 
                mutate(lon.Y = ifelse(lon.Y <= 0, lon.Y, lon.Y - 
                  360)), inherit.aes = F, alpha = alpha)
        }
        worldmap = worldmap + fillscale + scale_x_continuous(trans = lon_trans()) + 
            scale_y_continuous(trans = lat_trans()) + xlab("Longitude") + 
            ylab("Latitude")
        if (type %in% c("remote", "teleconnection", "eof", "remote_cor")) {
            worldmap = worldmap + geom_polygon()
        }
        else {
            worldmap = worldmap + geom_path()
        }
        if (signif.telecon) 
            if (sum(Y$signif) > 0) {
                worldmap = worldmap + geom_tile(tile.aes, data = Y %>% 
                  filter(signif == T), inherit.aes = F, color = "black", 
                  lwd = lwd, alpha = 1)
            }
        worldmap = worldmap + theme_grey() + ggtitle(t)
        if (!is.null(coords.knots)) {
            worldmap = worldmap + geom_point(aes(x = lon, y = lat), 
                data = coords.knots, col = "black", fill = "black", 
                shape = 21, inherit.aes = F)
        }
    }
    else {
        worldmap = ggplot(world, aes(x = long, y = lat, group = group)) + 
            geom_point(point.aes, data = Y %>% mutate(lon.Y = ifelse(lon.Y <= 
                0, lon.Y, lon.Y - 360)), inherit.aes = F, size = 4, 
                shape = 21) + fillscale + scale_color_manual("Significance", 
            values = c(True = "black", False = "grey")) + scale_x_continuous(trans = lon_trans()) + 
            scale_y_continuous(trans = lat_trans()) + xlab("Longitude") + 
            ylab("Latitude") + geom_path() + theme_grey() + ggtitle(t)
        if (!is.null(coords.knots)) {
            worldmap = worldmap + geom_point(aes(x = lon, y = lat), 
                data = coords.knots, col = "black", fill = "white", 
                shape = 21, inherit.aes = F)
        }
    }
    if (!is.null(coord.s)) {
        worldmap = worldmap + geom_point(aes(x = lon.Y, y = lat.Y), 
            data = data.frame(lon.Y = coord.s[1], lat.Y = coord.s[2]), 
            col = "black", fill = "white", shape = 21, inherit.aes = F)
        lon.E = max(lon.E, coord.s[1])
        lon.W = min(lon.W, coord.s[1])
        lat.N = max(lat.N, coord.s[2])
        lat.S = min(lat.S, coord.s[2])
    }
    worldmap + coord_fixed(xlim = c(lon.W, lon.E), ylim = c(lat.S, 
        lat.N), ratio = 1.3)
}
<bytecode: 0x3299c00>
<environment: namespace:telefit>
 --- function search by body ---
 ----------- END OF FAILURE REPORT -------------- 
Fatal error: the condition has length > 1