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

> ### Name: baron
> ### Title: Real Scuba Dive Profile
> ### Aliases: baron
> ### Keywords: datasets
> 
> ### ** Examples
> 
>   data(baron)
>   b <- dive(nitrox(0.30), baron[,1:2])
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
scuba
 --- call from context --- 
dive(nitrox(0.3), baron[, 1:2])
 --- call from argument --- 
if (newdepth != currentdepth) {
    duration <- timetaken(currentdepth, newdepth, rate.up, rate.down)
    state <- change(state, duration, newdepth)
    df <- rbind(df, state)
    now <- now + 1
}
 --- R stacktrace ---
where 1: dive(nitrox(0.3), baron[, 1:2])

 --- value of length: 606 type: logical ---
       time
  [1,] TRUE
  [2,] TRUE
  [3,] TRUE
  [4,] TRUE
  [5,] TRUE
  [6,] TRUE
  [7,] TRUE
  [8,] TRUE
  [9,] TRUE
 [10,] TRUE
 [11,] TRUE
 [12,] TRUE
 [13,] TRUE
 [14,] TRUE
 [15,] TRUE
 [16,] TRUE
 [17,] TRUE
 [18,] TRUE
 [19,] TRUE
 [20,] TRUE
 [21,] TRUE
 [22,] TRUE
 [23,] TRUE
 [24,] TRUE
 [25,] TRUE
 [26,] TRUE
 [27,] TRUE
 [28,] TRUE
 [29,] TRUE
 [30,] TRUE
 [31,] TRUE
 [32,] TRUE
 [33,] TRUE
 [34,] TRUE
 [35,] TRUE
 [36,] TRUE
 [37,] TRUE
 [38,] TRUE
 [39,] TRUE
 [40,] TRUE
 [41,] TRUE
 [42,] TRUE
 [43,] TRUE
 [44,] TRUE
 [45,] TRUE
 [46,] TRUE
 [47,] TRUE
 [48,] TRUE
 [49,] TRUE
 [50,] TRUE
 [51,] TRUE
 [52,] TRUE
 [53,] TRUE
 [54,] TRUE
 [55,] TRUE
 [56,] TRUE
 [57,] TRUE
 [58,] TRUE
 [59,] TRUE
 [60,] TRUE
 [61,] TRUE
 [62,] TRUE
 [63,] TRUE
 [64,] TRUE
 [65,] TRUE
 [66,] TRUE
 [67,] TRUE
 [68,] TRUE
 [69,] TRUE
 [70,] TRUE
 [71,] TRUE
 [72,] TRUE
 [73,] TRUE
 [74,] TRUE
 [75,] TRUE
 [76,] TRUE
 [77,] TRUE
 [78,] TRUE
 [79,] TRUE
 [80,] TRUE
 [81,] TRUE
 [82,] TRUE
 [83,] TRUE
 [84,] TRUE
 [85,] TRUE
 [86,] TRUE
 [87,] TRUE
 [88,] TRUE
 [89,] TRUE
 [90,] TRUE
 [91,] TRUE
 [92,] TRUE
 [93,] TRUE
 [94,] TRUE
 [95,] TRUE
 [96,] TRUE
 [97,] TRUE
 [98,] TRUE
 [99,] TRUE
[100,] TRUE
[101,] TRUE
[102,] TRUE
[103,] TRUE
[104,] TRUE
[105,] TRUE
[106,] TRUE
[107,] TRUE
[108,] TRUE
[109,] TRUE
[110,] TRUE
[111,] TRUE
[112,] TRUE
[113,] TRUE
[114,] TRUE
[115,] TRUE
[116,] TRUE
[117,] TRUE
[118,] TRUE
[119,] TRUE
[120,] TRUE
[121,] TRUE
[122,] TRUE
[123,] TRUE
[124,] TRUE
[125,] TRUE
[126,] TRUE
[127,] TRUE
[128,] TRUE
[129,] TRUE
[130,] TRUE
[131,] TRUE
[132,] TRUE
[133,] TRUE
[134,] TRUE
[135,] TRUE
[136,] TRUE
[137,] TRUE
[138,] TRUE
[139,] TRUE
[140,] TRUE
[141,] TRUE
[142,] TRUE
[143,] TRUE
[144,] TRUE
[145,] TRUE
[146,] TRUE
[147,] TRUE
[148,] TRUE
[149,] TRUE
[150,] TRUE
[151,] TRUE
[152,] TRUE
[153,] TRUE
[154,] TRUE
[155,] TRUE
[156,] TRUE
[157,] TRUE
[158,] TRUE
[159,] TRUE
[160,] TRUE
[161,] TRUE
[162,] TRUE
[163,] TRUE
[164,] TRUE
[165,] TRUE
[166,] TRUE
[167,] TRUE
[168,] TRUE
[169,] TRUE
[170,] TRUE
[171,] TRUE
[172,] TRUE
[173,] TRUE
[174,] TRUE
[175,] TRUE
[176,] TRUE
[177,] TRUE
[178,] TRUE
[179,] TRUE
[180,] TRUE
[181,] TRUE
[182,] TRUE
[183,] TRUE
[184,] TRUE
[185,] TRUE
[186,] TRUE
[187,] TRUE
[188,] TRUE
[189,] TRUE
[190,] TRUE
[191,] TRUE
[192,] TRUE
[193,] TRUE
[194,] TRUE
[195,] TRUE
[196,] TRUE
[197,] TRUE
[198,] TRUE
[199,] TRUE
[200,] TRUE
[201,] TRUE
[202,] TRUE
[203,] TRUE
[204,] TRUE
[205,] TRUE
[206,] TRUE
[207,] TRUE
[208,] TRUE
[209,] TRUE
[210,] TRUE
[211,] TRUE
[212,] TRUE
[213,] TRUE
[214,] TRUE
[215,] TRUE
[216,] TRUE
[217,] TRUE
[218,] TRUE
[219,] TRUE
[220,] TRUE
[221,] TRUE
[222,] TRUE
[223,] TRUE
[224,] TRUE
[225,] TRUE
[226,] TRUE
[227,] TRUE
[228,] TRUE
[229,] TRUE
[230,] TRUE
[231,] TRUE
[232,] TRUE
[233,] TRUE
[234,] TRUE
[235,] TRUE
[236,] TRUE
[237,] TRUE
[238,] TRUE
[239,] TRUE
[240,] TRUE
[241,] TRUE
[242,] TRUE
[243,] TRUE
[244,] TRUE
[245,] TRUE
[246,] TRUE
[247,] TRUE
[248,] TRUE
[249,] TRUE
[250,] TRUE
[251,] TRUE
[252,] TRUE
[253,] TRUE
[254,] TRUE
[255,] TRUE
[256,] TRUE
[257,] TRUE
[258,] TRUE
[259,] TRUE
[260,] TRUE
[261,] TRUE
[262,] TRUE
[263,] TRUE
[264,] TRUE
[265,] TRUE
[266,] TRUE
[267,] TRUE
[268,] TRUE
[269,] TRUE
[270,] TRUE
[271,] TRUE
[272,] TRUE
[273,] TRUE
[274,] TRUE
[275,] TRUE
[276,] TRUE
[277,] TRUE
[278,] TRUE
[279,] TRUE
[280,] TRUE
[281,] TRUE
[282,] TRUE
[283,] TRUE
[284,] TRUE
[285,] TRUE
[286,] TRUE
[287,] TRUE
[288,] TRUE
[289,] TRUE
[290,] TRUE
[291,] TRUE
[292,] TRUE
[293,] TRUE
[294,] TRUE
[295,] TRUE
[296,] TRUE
[297,] TRUE
[298,] TRUE
[299,] TRUE
[300,] TRUE
[301,] TRUE
[302,] TRUE
[303,] TRUE
[304,] TRUE
[305,] TRUE
[306,] TRUE
[307,] TRUE
[308,] TRUE
[309,] TRUE
[310,] TRUE
[311,] TRUE
[312,] TRUE
[313,] TRUE
[314,] TRUE
[315,] TRUE
[316,] TRUE
[317,] TRUE
[318,] TRUE
[319,] TRUE
[320,] TRUE
[321,] TRUE
[322,] TRUE
[323,] TRUE
[324,] TRUE
[325,] TRUE
[326,] TRUE
[327,] TRUE
[328,] TRUE
[329,] TRUE
[330,] TRUE
[331,] TRUE
[332,] TRUE
[333,] TRUE
[334,] TRUE
[335,] TRUE
[336,] TRUE
[337,] TRUE
[338,] TRUE
[339,] TRUE
[340,] TRUE
[341,] TRUE
[342,] TRUE
[343,] TRUE
[344,] TRUE
[345,] TRUE
[346,] TRUE
[347,] TRUE
[348,] TRUE
[349,] TRUE
[350,] TRUE
[351,] TRUE
[352,] TRUE
[353,] TRUE
[354,] TRUE
[355,] TRUE
[356,] TRUE
[357,] TRUE
[358,] TRUE
[359,] TRUE
[360,] TRUE
[361,] TRUE
[362,] TRUE
[363,] TRUE
[364,] TRUE
[365,] TRUE
[366,] TRUE
[367,] TRUE
[368,] TRUE
[369,] TRUE
[370,] TRUE
[371,] TRUE
[372,] TRUE
[373,] TRUE
[374,] TRUE
[375,] TRUE
[376,] TRUE
[377,] TRUE
[378,] TRUE
[379,] TRUE
[380,] TRUE
[381,] TRUE
[382,] TRUE
[383,] TRUE
[384,] TRUE
[385,] TRUE
[386,] TRUE
[387,] TRUE
[388,] TRUE
[389,] TRUE
[390,] TRUE
[391,] TRUE
[392,] TRUE
[393,] TRUE
[394,] TRUE
[395,] TRUE
[396,] TRUE
[397,] TRUE
[398,] TRUE
[399,] TRUE
[400,] TRUE
[401,] TRUE
[402,] TRUE
[403,] TRUE
[404,] TRUE
[405,] TRUE
[406,] TRUE
[407,] TRUE
[408,] TRUE
[409,] TRUE
[410,] TRUE
[411,] TRUE
[412,] TRUE
[413,] TRUE
[414,] TRUE
[415,] TRUE
[416,] TRUE
[417,] TRUE
[418,] TRUE
[419,] TRUE
[420,] TRUE
[421,] TRUE
[422,] TRUE
[423,] TRUE
[424,] TRUE
[425,] TRUE
[426,] TRUE
[427,] TRUE
[428,] TRUE
[429,] TRUE
[430,] TRUE
[431,] TRUE
[432,] TRUE
[433,] TRUE
[434,] TRUE
[435,] TRUE
[436,] TRUE
[437,] TRUE
[438,] TRUE
[439,] TRUE
[440,] TRUE
[441,] TRUE
[442,] TRUE
[443,] TRUE
[444,] TRUE
[445,] TRUE
[446,] TRUE
[447,] TRUE
[448,] TRUE
[449,] TRUE
[450,] TRUE
[451,] TRUE
[452,] TRUE
[453,] TRUE
[454,] TRUE
[455,] TRUE
[456,] TRUE
[457,] TRUE
[458,] TRUE
[459,] TRUE
[460,] TRUE
[461,] TRUE
[462,] TRUE
[463,] TRUE
[464,] TRUE
[465,] TRUE
[466,] TRUE
[467,] TRUE
[468,] TRUE
[469,] TRUE
[470,] TRUE
[471,] TRUE
[472,] TRUE
[473,] TRUE
[474,] TRUE
[475,] TRUE
[476,] TRUE
[477,] TRUE
[478,] TRUE
[479,] TRUE
[480,] TRUE
[481,] TRUE
[482,] TRUE
[483,] TRUE
[484,] TRUE
[485,] TRUE
[486,] TRUE
[487,] TRUE
[488,] TRUE
[489,] TRUE
[490,] TRUE
[491,] TRUE
[492,] TRUE
[493,] TRUE
[494,] TRUE
[495,] TRUE
[496,] TRUE
[497,] TRUE
[498,] TRUE
[499,] TRUE
[500,] TRUE
[501,] TRUE
[502,] TRUE
[503,] TRUE
[504,] TRUE
[505,] TRUE
[506,] TRUE
[507,] TRUE
[508,] TRUE
[509,] TRUE
[510,] TRUE
[511,] TRUE
[512,] TRUE
[513,] TRUE
[514,] TRUE
[515,] TRUE
[516,] TRUE
[517,] TRUE
[518,] TRUE
[519,] TRUE
[520,] TRUE
[521,] TRUE
[522,] TRUE
[523,] TRUE
[524,] TRUE
[525,] TRUE
[526,] TRUE
[527,] TRUE
[528,] TRUE
[529,] TRUE
[530,] TRUE
[531,] TRUE
[532,] TRUE
[533,] TRUE
[534,] TRUE
[535,] TRUE
[536,] TRUE
[537,] TRUE
[538,] TRUE
[539,] TRUE
[540,] TRUE
[541,] TRUE
[542,] TRUE
[543,] TRUE
[544,] TRUE
[545,] TRUE
[546,] TRUE
[547,] TRUE
[548,] TRUE
[549,] TRUE
[550,] TRUE
[551,] TRUE
[552,] TRUE
[553,] TRUE
[554,] TRUE
[555,] TRUE
[556,] TRUE
[557,] TRUE
[558,] TRUE
[559,] TRUE
[560,] TRUE
[561,] TRUE
[562,] TRUE
[563,] TRUE
[564,] TRUE
[565,] TRUE
[566,] TRUE
[567,] TRUE
[568,] TRUE
[569,] TRUE
[570,] TRUE
[571,] TRUE
[572,] TRUE
[573,] TRUE
[574,] TRUE
[575,] TRUE
[576,] TRUE
[577,] TRUE
[578,] TRUE
[579,] TRUE
[580,] TRUE
[581,] TRUE
[582,] TRUE
[583,] TRUE
[584,] TRUE
[585,] TRUE
[586,] TRUE
[587,] TRUE
[588,] TRUE
[589,] TRUE
[590,] TRUE
[591,] TRUE
[592,] TRUE
[593,] TRUE
[594,] TRUE
[595,] TRUE
[596,] TRUE
[597,] TRUE
[598,] TRUE
[599,] TRUE
[600,] TRUE
[601,] TRUE
[602,] TRUE
[603,] TRUE
[604,] TRUE
[605,] TRUE
[606,] TRUE
 --- function from context --- 
function (..., begin = 0, end = 0, tanklist = NULL) 
{
    X <- list(...)
    if (length(X) == 0) 
        stop("No dive profile supplied")
    if (!is.na(begin)) 
        stopifnot(is.numeric(begin) && length(begin) == 1)
    if (!is.na(end)) 
        stopifnot(is.numeric(end) && length(end) == 1)
    tanks.given <- !is.null(tanklist)
    gases.given <- tanks.given || any(unlist(lapply(X, is.gas)))
    tanks.implied <- FALSE
    state <- data.frame(time = 0, depth = begin, fO2 = air$fO2, 
        fN2 = air$fN2, fHe = air$fHe, tankid = 1)
    rate.down <- descent(30)
    rate.up <- ascent(18)
    if (!tanks.given) 
        tanklist <- list(air)
    df <- state
    now <- 1
    tagged <- nzchar(names(X))
    if (length(tagged) == 0) 
        tagged <- rep(FALSE, length(X))
    change <- function(state, duration = NULL, depth = NULL, 
        fO2 = NULL, fN2 = NULL, fHe = NULL, tankid = NULL) {
        if (!is.null(duration)) 
            state$time <- state$time + duration
        if (!is.null(depth)) 
            state$depth <- depth
        if (!is.null(fO2)) 
            state$fO2 <- fO2
        if (!is.null(fN2)) 
            state$fN2 <- fN2
        if (!is.null(fHe)) 
            state$fHe <- fHe
        if (!is.null(tankid)) 
            state$tankid <- tankid
        return(state)
    }
    gasequal <- function(g1, g2) {
        identical(all.equal(g1, g2), TRUE)
    }
    for (i in seq(X)) {
        Y <- X[[i]]
        if (is.rate(Y)) 
            if (Y$up) 
                rate.up <- Y
            else rate.down <- Y
        else if (is.gas(Y)) {
            if (tanks.given) 
                stop(paste("If tanklist is given, gas switches should indicate", 
                  "which tank is used (tank=number or tank=name)"))
            matched <- unlist(lapply(tanklist, gasequal, g2 = Y))
            if (any(matched)) 
                tankid <- min(which(matched))
            else {
                if (now == 1) 
                  tanklist <- list(Y)
                else tanklist <- append(tanklist, list(Y))
                tankid <- length(tanklist)
            }
            state <- change(state, fO2 = Y$fO2, fN2 = Y$fN2, 
                fHe = Y$fHe, tankid = tankid)
            df[now, ] <- state
        }
        else if (tanks.given && tagged[i] && names(X)[i] == "tank") {
            if (is.null(tanklist)) 
                stop("Cannot change tank: no tanks specified")
            Z <- tanklist[[Y]]
            state <- change(state, fO2 = Z$fO2, fN2 = Z$fN2, 
                fHe = Z$fHe, tankid = Y)
            df[now, ] <- state
        }
        else if (is.vector(Y)) {
            if (length(Y) > 2) 
                stop("Vector of length > 2 is not a recognised format")
            newdepth <- Y[1]
            currentdepth <- state$depth
            if (is.na(currentdepth)) {
                state <- change(state, depth = newdepth)
            }
            else if (newdepth != currentdepth) {
                duration <- timetaken(currentdepth, newdepth, 
                  rate.up, rate.down)
                state <- change(state, duration, newdepth)
                df <- rbind(df, state)
                now <- now + 1
            }
            if (length(Y) > 1) {
                duration <- Y[2]
                state <- change(state, duration)
                df <- rbind(df, state)
                now <- now + 1
            }
        }
        else if (is.data.frame(Y)) {
            if (ncol(Y) != 2) 
                stop("Data frame should have 2 columns")
            newtimes <- Y[, 1]
            newdepths <- Y[, 2]
            nsteps <- nrow(Y)
            if (inherits(newtimes, "difftime")) {
                units(newtimes) <- "mins"
                newtimes <- as.numeric(newtimes)
            }
            else if (is.numeric(newtimes)) {
                message("Elapsed times are assumed to be given in seconds (and are converted to minutes)")
                newtimes <- newtimes/60
            }
            else if (is.character(newtimes)) {
                zip <- function(x) {
                  x <- as.numeric(x)
                  n <- length(x)
                  secs <- sum(x * 60^((n - 1):0))
                  return(secs/60)
                }
                newtimes <- unlist(lapply(strsplit(newtimes, 
                  ":"), zip))
            }
            else stop("Unknown format for elapsed times")
            if (any(is.na(newtimes))) 
                stop("Unable to convert times")
            if (!all(diff(newtimes) > 0)) 
                stop("Elapsed times are not an increasing sequence")
            newtimes <- newtimes + state$time
            newdf <- data.frame(time = newtimes, depth = newdepths, 
                fO2 = state$fO2, fN2 = state$fN2, fHe = state$fHe)
            if (!is.null(tanklist)) 
                newdf <- cbind(newdf, tankid = state$tankid)
            currentdepth <- state$depth
            if (is.na(currentdepth)) {
                df <- newdf
            }
            else {
                if (newdepths[1] != currentdepth) {
                  duration <- timetaken(currentdepth, newdepths[1], 
                    rate.up, rate.down)
                  newdf$time <- newdf$time + duration
                }
                else if (newtimes[1] == state$time) {
                  df <- df[-now, ]
                }
                df <- rbind(df, newdf)
            }
            now <- nrow(df)
            state <- df[now, ]
        }
        else if (is.dive(Y)) {
            Ydata <- Y$data
            newdepth <- Ydata$depth[1]
            if (newdepth != state$depth) {
                duration <- timetaken(state$depth, newdepth, 
                  rate.up, rate.down)
                state <- change(state, duration, newdepth)
                df <- rbind(df, state)
                now <- now + 1
            }
            else {
                df <- df[-now, ]
            }
            if (gases.given) {
                Ydata$tankid <- state$tankid
                Ydata$fO2 <- state$fO2
                Ydata$fN2 <- state$fN2
                Ydata$fHe <- state$fHe
            }
            else {
                if (now == 1) {
                  tanklist <- Y$tanklist
                  tanks.implied <- tanks.implied || Y$tanks.given
                }
                else if (!Y$tanks.given) {
                  Ydata$tankid <- state$tankid
                  Ydata$fO2 <- state$fO2
                  Ydata$fN2 <- state$fN2
                  Ydata$fHe <- state$fHe
                }
                else {
                  tanks.implied <- TRUE
                  tid <- df$tankid
                  Ytid <- Ydata$tankid
                  if (is.factor(tid) && is.factor(Ytid)) {
                    if (!identical(tanklist, Y$tanklist) || !identical(levels(tid), 
                      levels(Ytid))) {
                      tidN <- length(levels(tid))
                      YtidN <- length(levels(Ytid))
                      lev <- c(levels(tid), levels(Ytid))
                      tid <- factor(tid, levels = lev)
                      Ytid <- factor(as.integer(Ytid) + tidN, 
                        levels = seq(tidN + YtidN))
                      levels(Ytid) <- lev
                      df$tankid <- tid
                      Ydata$tankid <- Ytid
                      tanklist <- append(tanklist, Y$tanklist)
                    }
                  }
                  else {
                    df$tankid <- as.integer(tid)
                    Ydata$tankid <- as.integer(Ydata$tankid) + 
                      length(tanklist)
                    tanklist <- append(tanklist, Y$tanklist)
                  }
                  Ydata <- reconcile.df(Ydata, tanklist)
                }
            }
            Ydata$time <- (Ydata$time - Ydata$time[1]) + state$time
            df <- rbind(df, Ydata)
            state <- df[nrow(df), ]
            now <- nrow(df) + 1
        }
        else stop(paste("The format of argument", i, "is not recognised\n"))
    }
    if (!is.na(end) && state$depth != end) {
        duration <- timetaken(state$depth, end, rate.up, rate.down)
        state <- change(state, duration, end)
        df <- rbind(df, state)
        now <- now + 1
    }
    if (any(df$depth < 0)) {
        warning("Some depths were less than 0; they were reset to 0")
        df$depth <- pmax(0, df$depth)
    }
    airdive <- all(with(df, gasnames(fO2, fN2, fHe)) == "air")
    if (is.character(df$tankid)) {
        nama <- names(tanklist)
        if (is.null(nama)) 
            nama <- paste(seq(tanklist))
        df$tankid <- factor(df$tankid, levels = nama)
    }
    if (nrow(df) <= 1) 
        stop("Need at least two waypoints for a dive")
    pro <- approxfun(df$time, df$depth, method = "linear", rule = 2, 
        ties = "ordered")
    result <- list(profile = pro, data = df, airdive = airdive, 
        tanklist = tanklist, tanks.given = tanks.given || tanks.implied)
    class(result) <- c("dive", class(result))
    return(result)
}
<bytecode: 0x2e6dbc0>
<environment: namespace:scuba>
 --- function search by body ---
Function dive in namespace scuba has this body.
 ----------- END OF FAILURE REPORT -------------- 
Error in if (newdepth != currentdepth) { : the condition has length > 1
Calls: dive
Execution halted