Running ‘test_survPen.r’ [1s/2s]
  Running ‘testthat.R’ [2s/3s]
Running the tests in ‘tests/test_survPen.r’ failed.
Complete output:
  > #--------------------------------------------------------------------------------------------------------------------------
  > # test code for survPen package
  > #--------------------------------------------------------------------------------------------------------------------------
  > 
  > 
  >  library(survPen)
  >  library(splines)
  >  data(datCancer) # simulated dataset with 2000 individuals diagnosed with cervical cancer
  >  
  >  
  >  cat("\n","______________________________________________________________________________________________","\n")
  
   ______________________________________________________________________________________________ 
  >  cat("\n","survPen test code","\n")
  
   survPen test code 
  >  cat("\n","______________________________________________________________________________________________","\n")
  
   ______________________________________________________________________________________________ 
  > 
  >  
  >  #-------------------------------------------------------- example 0
  >  # Comparison between restricted cubic splines and penalized restricted cubic splines
  >  cat("\n","______________________________________________________________________________________________","\n")
  
   ______________________________________________________________________________________________ 
  >  cat("\n","example 0","\n")
  
   example 0 
  >  cat("\n","Comparison between restricted cubic splines and penalized restricted cubic splines","\n")
  
   Comparison between restricted cubic splines and penalized restricted cubic splines 
  >  
  > 
  > 
  >  # unpenalized
  >  f <- ~ns(fu,knots=c(0.25, 0.5, 1, 2, 4),Boundary.knots=c(0,5))
  > 
  >  mod <- survPen(f,data=datCancer,t1=fu,event=dead)
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  survPen
   --- call from context --- 
  NR.beta(build, beta.ini, detail.beta = detail.beta, max.it.beta = max.it.beta, 
      tol.beta = tol.beta)
   --- call from argument --- 
  if (class(R) == "Error" | class(R) == "try-error") {
      u = 0.001
      cpt.while <- 0
      while (class(R) == "Error" | class(R) == "try-error") {
          if (cpt.while > 100) {
              stop("message NR.beta: did not succeed in inverting Hessian at iteration ", 
                  k)
          }
          R <- try(chol(neg.Hess + u * diag(p)), silent = TRUE)
          u <- 5 * u
          cpt.while <- cpt.while + 1
      }
      if (detail.beta) {
          cat("beta Hessian perturbation, ", cpt.while, "iterations", 
              "\n", "\n")
      }
  }
   --- R stacktrace ---
  where 1: NR.beta(build, beta.ini, detail.beta = detail.beta, max.it.beta = max.it.beta, 
      tol.beta = tol.beta)
  where 2: survPen.fit(build, data = data, formula = formula, max.it.beta = max.it.beta, 
      beta.ini = beta.ini, detail.beta = detail.beta, method = method, 
      tol.beta = tol.beta)
  where 3: survPen(f, data = datCancer, t1 = fu, event = dead)
  
   --- value of length: 2 type: logical ---
  [1] FALSE FALSE
   --- function from context --- 
  function (build, beta.ini, detail.beta, max.it.beta = 200, tol.beta = 1e-04) 
  {
      type <- build$type
      X <- build$X
      T.X <- build$T.X
      X.GL <- build$X.GL
      T.X.GL <- build$T.X.GL
      X.GL.w.tm <- build$X.GL.w.tm
      event <- build$event
      eventX <- build$eventX
      expected <- build$expected
      eventXexpected <- build$eventXexpected
      leg <- build$leg
      n.legendre <- build$n.legendre
      t1 <- build$t1
      t0 <- build$t0
      tm <- build$tm
      S <- build$S
      p <- build$p
      k = 1
      ll.pen = 100
      ll.pen.old = 1
      if (length(beta.ini) == 1) 
          beta.ini <- rep(beta.ini, p)
      if (length(beta.ini) != p) 
          stop("message NR.beta: the length of beta.ini does not equal the number of regression parameters")
      betaold <- beta.ini
      beta1 <- betaold
      if (detail.beta) {
          cat("---------------------------------------------------------------------------------------", 
              "\n", "Beginning regression parameter estimation", 
              "\n", "\n")
      }
      while (abs(ll.pen - ll.pen.old) > tol.beta | any(abs((beta1 - 
          betaold)/betaold) > tol.beta)) {
          if (k > max.it.beta) {
              stop("message NR.beta: Ran out of iterations (", 
                  k, "), and did not converge ")
          }
          if (k >= 2) {
              ll.pen.old <- ll.pen
              betaold <- beta1
          }
          predold = as.vector(X %*% betaold)
          ftold = as.vector(exp(predold))
          haz.GL.old <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
              betaold)))
          deriv.list <- lapply(1:n.legendre, function(i) X.GL.w.tm[[i]] * 
              haz.GL.old[[i]])
          f.first <- Reduce("+", deriv.list)
          if (type == "net") {
              grad.unpen.beta <- colSums(-f.first + (eventX * ftold)/(ftold + 
                  expected))
          }
          else {
              grad.unpen.beta <- colSums(-f.first + eventX)
          }
          grad <- grad.unpen.beta - as.vector(S %*% betaold)
          deriv.2.list <- lapply(1:n.legendre, function(i) T.X.GL[[i]] %*% 
              (deriv.list[[i]]))
          f.second <- Reduce("+", deriv.2.list)
          if (type == "net") {
              Hess.unpen <- -f.second + T.X %*% (eventXexpected * 
                  ftold/(ftold + expected)^2)
          }
          else {
              Hess.unpen <- -f.second
          }
          Hess <- Hess.unpen - S
          neg.Hess <- -Hess
          R <- try(chol(neg.Hess), silent = TRUE)
          if (class(R) == "Error" | class(R) == "try-error") {
              u = 0.001
              cpt.while <- 0
              while (class(R) == "Error" | class(R) == "try-error") {
                  if (cpt.while > 100) {
                    stop("message NR.beta: did not succeed in inverting Hessian at iteration ", 
                      k)
                  }
                  R <- try(chol(neg.Hess + u * diag(p)), silent = TRUE)
                  u <- 5 * u
                  cpt.while <- cpt.while + 1
              }
              if (detail.beta) {
                  cat("beta Hessian perturbation, ", cpt.while, 
                    "iterations", "\n", "\n")
              }
          }
          neg.inv.Hess <- chol2inv(R)
          integral <- lapply(1:n.legendre, function(i) haz.GL.old[[i]] * 
              leg$weights[i])
          integral <- tm * Reduce("+", integral)
          if (type == "net") {
              ll.unpenold <- sum(-integral + event * log(ftold + 
                  expected))
          }
          else {
              ll.unpenold <- sum(-integral + event * predold)
          }
          ll.pen.old <- ll.unpenold - as.numeric(t(betaold) %*% 
              S %*% betaold) * 0.5
          if (is.nan(ll.pen.old)) 
              stop("message NR.beta: convergence issues, cannot evaluate log-likelihood")
          pas <- as.vector(neg.inv.Hess %*% grad)
          beta1 <- betaold + pas
          pred1 <- as.vector(X %*% beta1)
          ft1 = as.vector(exp(pred1))
          haz.GL <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
              beta1)))
          integral <- lapply(1:n.legendre, function(i) haz.GL[[i]] * 
              leg$weights[i])
          integral <- tm * Reduce("+", integral)
          if (type == "net") {
              ll.unpen <- sum(-integral + event * log(ft1 + expected))
          }
          else {
              ll.unpen <- sum(-integral + event * pred1)
          }
          ll.pen <- ll.unpen - as.numeric(t(beta1) %*% S %*% beta1) * 
              0.5
          if (is.nan(ll.pen)) {
              ll.pen <- ll.pen.old - 1
          }
          if (ll.pen < ll.pen.old - 0.001) {
              cpt.beta <- 1
              while (ll.pen < ll.pen.old - 0.001) {
                  if (cpt.beta > 52) 
                    stop("message NR.beta: step has been divided by two 52 times in a row, Log-likelihood could not be optimized")
                  cpt.beta <- cpt.beta + 1
                  pas <- 0.5 * pas
                  beta1 <- betaold + pas
                  pred1 <- as.vector(X %*% beta1)
                  ft1 = as.vector(exp(pred1))
                  haz.GL <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
                    beta1)))
                  integral <- lapply(1:n.legendre, function(i) haz.GL[[i]] * 
                    leg$weights[i])
                  integral <- tm * Reduce("+", integral)
                  if (type == "net") {
                    ll.unpen <- sum(-integral + event * log(ft1 + 
                      expected))
                  }
                  else {
                    ll.unpen <- sum(-integral + event * pred1)
                  }
                  ll.pen <- ll.unpen - as.numeric(t(beta1) %*% 
                    S %*% beta1) * 0.5
                  if (is.nan(ll.pen)) {
                    ll.pen <- ll.pen.old - 1
                  }
              }
          }
          if (detail.beta) {
              cat("iter beta: ", k, "\n", "betaold= ", round(betaold, 
                  4), "\n", "beta= ", round(beta1, 4), "\n", "abs((beta-betaold)/betaold)= ", 
                  round(abs((beta1 - betaold)/betaold), 5), "\n", 
                  "ll.pen.old= ", round(ll.pen.old, 4), "\n", "ll.pen= ", 
                  round(ll.pen, 4), "\n", "ll.pen-ll.pen.old= ", 
                  round(ll.pen - ll.pen.old, 5), "\n", "\n")
          }
          k = k + 1
      }
      if (detail.beta) {
          cat("\n", "Beta optimization ok, ", k - 1, "iterations", 
              "\n", "--------------------------------------------------------------------------------------", 
              "\n")
      }
      list(beta = beta1, ll.unpen = ll.unpen, ll.pen = ll.pen, 
          haz.GL = haz.GL, iter.beta = k - 1)
  }
  <bytecode: 0x5584ac8c0f10>
  <environment: namespace:survPen>
   --- function search by body ---
  Function NR.beta in namespace survPen has this body.
   ----------- END OF FAILURE REPORT -------------- 
  Fatal error: the condition has length > 1
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
  > library(testthat)
  > library(survPen)
  > 
  > test_check("survPen")
   ----------- FAILURE REPORT -------------- 
   --- failure: the condition has length > 1 ---
   --- srcref --- 
  : 
   --- package (from environment) --- 
  survPen
   --- call from context --- 
  NR.beta(build, beta.ini, detail.beta = detail.beta, max.it.beta = max.it.beta, 
      tol.beta = tol.beta)
   --- call from argument --- 
  if (class(R) == "Error" | class(R) == "try-error") {
      u = 0.001
      cpt.while <- 0
      while (class(R) == "Error" | class(R) == "try-error") {
          if (cpt.while > 100) {
              stop("message NR.beta: did not succeed in inverting Hessian at iteration ", 
                  k)
          }
          R <- try(chol(neg.Hess + u * diag(p)), silent = TRUE)
          u <- 5 * u
          cpt.while <- cpt.while + 1
      }
      if (detail.beta) {
          cat("beta Hessian perturbation, ", cpt.while, "iterations", 
              "\n", "\n")
      }
  }
   --- R stacktrace ---
  where 1: NR.beta(build, beta.ini, detail.beta = detail.beta, max.it.beta = max.it.beta, 
      tol.beta = tol.beta)
  where 2 at testthat/test_Newton.R#19: survPen.fit(model.c, data, form)
  where 3: eval(code, test_env)
  where 4: eval(code, test_env)
  where 5: withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error)
  where 6: doTryCatch(return(expr), name, parentenv, handler)
  where 7: tryCatchOne(expr, names, parentenv, handlers[[1L]])
  where 8: tryCatchList(expr, names[-nh], parentenv, handlers[-nh])
  where 9: doTryCatch(return(expr), name, parentenv, handler)
  where 10: tryCatchOne(tryCatchList(expr, names[-nh], parentenv, handlers[-nh]), 
      names[nh], parentenv, handlers[[nh]])
  where 11: tryCatchList(expr, classes, parentenv, handlers)
  where 12: tryCatch(withCallingHandlers({
      eval(code, test_env)
      if (!handled && !is.null(test)) {
          skip_empty()
      }
  }, expectation = handle_expectation, skip = handle_skip, warning = handle_warning, 
      message = handle_message, error = handle_error), error = handle_fatal, 
      skip = function(e) {
      })
  where 13: test_code(NULL, exprs, env)
  where 14: source_file(path, new.env(parent = env), chdir = TRUE, wrap = wrap)
  where 15: force(code)
  where 16: doWithOneRestart(return(expr), restart)
  where 17: withOneRestart(expr, restarts[[1L]])
  where 18: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 19: with_reporter(reporter = reporter, start_end_reporter = start_end_reporter, 
      {
          reporter$start_file(basename(path))
          lister$start_file(basename(path))
          source_file(path, new.env(parent = env), chdir = TRUE, 
              wrap = wrap)
          reporter$.end_context()
          reporter$end_file()
      })
  where 20: FUN(X[[i]], ...)
  where 21: lapply(paths, test_file, env = env, reporter = current_reporter, 
      start_end_reporter = FALSE, load_helpers = FALSE, wrap = wrap)
  where 22: force(code)
  where 23: doWithOneRestart(return(expr), restart)
  where 24: withOneRestart(expr, restarts[[1L]])
  where 25: withRestarts(testthat_abort_reporter = function() NULL, force(code))
  where 26: with_reporter(reporter = current_reporter, results <- lapply(paths, 
      test_file, env = env, reporter = current_reporter, start_end_reporter = FALSE, 
      load_helpers = FALSE, wrap = wrap))
  where 27: test_files(paths, reporter = reporter, env = env, stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 28: test_dir(path = test_path, reporter = reporter, env = env, filter = filter, 
      ..., stop_on_failure = stop_on_failure, stop_on_warning = stop_on_warning, 
      wrap = wrap)
  where 29: test_package_dir(package = package, test_path = test_path, filter = filter, 
      reporter = reporter, ..., stop_on_failure = stop_on_failure, 
      stop_on_warning = stop_on_warning, wrap = wrap)
  where 30: test_check("survPen")
  
   --- value of length: 2 type: logical ---
  [1] FALSE FALSE
   --- function from context --- 
  function (build, beta.ini, detail.beta, max.it.beta = 200, tol.beta = 1e-04) 
  {
      type <- build$type
      X <- build$X
      T.X <- build$T.X
      X.GL <- build$X.GL
      T.X.GL <- build$T.X.GL
      X.GL.w.tm <- build$X.GL.w.tm
      event <- build$event
      eventX <- build$eventX
      expected <- build$expected
      eventXexpected <- build$eventXexpected
      leg <- build$leg
      n.legendre <- build$n.legendre
      t1 <- build$t1
      t0 <- build$t0
      tm <- build$tm
      S <- build$S
      p <- build$p
      k = 1
      ll.pen = 100
      ll.pen.old = 1
      if (length(beta.ini) == 1) 
          beta.ini <- rep(beta.ini, p)
      if (length(beta.ini) != p) 
          stop("message NR.beta: the length of beta.ini does not equal the number of regression parameters")
      betaold <- beta.ini
      beta1 <- betaold
      if (detail.beta) {
          cat("---------------------------------------------------------------------------------------", 
              "\n", "Beginning regression parameter estimation", 
              "\n", "\n")
      }
      while (abs(ll.pen - ll.pen.old) > tol.beta | any(abs((beta1 - 
          betaold)/betaold) > tol.beta)) {
          if (k > max.it.beta) {
              stop("message NR.beta: Ran out of iterations (", 
                  k, "), and did not converge ")
          }
          if (k >= 2) {
              ll.pen.old <- ll.pen
              betaold <- beta1
          }
          predold = as.vector(X %*% betaold)
          ftold = as.vector(exp(predold))
          haz.GL.old <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
              betaold)))
          deriv.list <- lapply(1:n.legendre, function(i) X.GL.w.tm[[i]] * 
              haz.GL.old[[i]])
          f.first <- Reduce("+", deriv.list)
          if (type == "net") {
              grad.unpen.beta <- colSums(-f.first + (eventX * ftold)/(ftold + 
                  expected))
          }
          else {
              grad.unpen.beta <- colSums(-f.first + eventX)
          }
          grad <- grad.unpen.beta - as.vector(S %*% betaold)
          deriv.2.list <- lapply(1:n.legendre, function(i) T.X.GL[[i]] %*% 
              (deriv.list[[i]]))
          f.second <- Reduce("+", deriv.2.list)
          if (type == "net") {
              Hess.unpen <- -f.second + T.X %*% (eventXexpected * 
                  ftold/(ftold + expected)^2)
          }
          else {
              Hess.unpen <- -f.second
          }
          Hess <- Hess.unpen - S
          neg.Hess <- -Hess
          R <- try(chol(neg.Hess), silent = TRUE)
          if (class(R) == "Error" | class(R) == "try-error") {
              u = 0.001
              cpt.while <- 0
              while (class(R) == "Error" | class(R) == "try-error") {
                  if (cpt.while > 100) {
                    stop("message NR.beta: did not succeed in inverting Hessian at iteration ", 
                      k)
                  }
                  R <- try(chol(neg.Hess + u * diag(p)), silent = TRUE)
                  u <- 5 * u
                  cpt.while <- cpt.while + 1
              }
              if (detail.beta) {
                  cat("beta Hessian perturbation, ", cpt.while, 
                    "iterations", "\n", "\n")
              }
          }
          neg.inv.Hess <- chol2inv(R)
          integral <- lapply(1:n.legendre, function(i) haz.GL.old[[i]] * 
              leg$weights[i])
          integral <- tm * Reduce("+", integral)
          if (type == "net") {
              ll.unpenold <- sum(-integral + event * log(ftold + 
                  expected))
          }
          else {
              ll.unpenold <- sum(-integral + event * predold)
          }
          ll.pen.old <- ll.unpenold - as.numeric(t(betaold) %*% 
              S %*% betaold) * 0.5
          if (is.nan(ll.pen.old)) 
              stop("message NR.beta: convergence issues, cannot evaluate log-likelihood")
          pas <- as.vector(neg.inv.Hess %*% grad)
          beta1 <- betaold + pas
          pred1 <- as.vector(X %*% beta1)
          ft1 = as.vector(exp(pred1))
          haz.GL <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
              beta1)))
          integral <- lapply(1:n.legendre, function(i) haz.GL[[i]] * 
              leg$weights[i])
          integral <- tm * Reduce("+", integral)
          if (type == "net") {
              ll.unpen <- sum(-integral + event * log(ft1 + expected))
          }
          else {
              ll.unpen <- sum(-integral + event * pred1)
          }
          ll.pen <- ll.unpen - as.numeric(t(beta1) %*% S %*% beta1) * 
              0.5
          if (is.nan(ll.pen)) {
              ll.pen <- ll.pen.old - 1
          }
          if (ll.pen < ll.pen.old - 0.001) {
              cpt.beta <- 1
              while (ll.pen < ll.pen.old - 0.001) {
                  if (cpt.beta > 52) 
                    stop("message NR.beta: step has been divided by two 52 times in a row, Log-likelihood could not be optimized")
                  cpt.beta <- cpt.beta + 1
                  pas <- 0.5 * pas
                  beta1 <- betaold + pas
                  pred1 <- as.vector(X %*% beta1)
                  ft1 = as.vector(exp(pred1))
                  haz.GL <- lapply(1:n.legendre, function(i) as.vector(exp(X.GL[[i]] %*% 
                    beta1)))
                  integral <- lapply(1:n.legendre, function(i) haz.GL[[i]] * 
                    leg$weights[i])
                  integral <- tm * Reduce("+", integral)
                  if (type == "net") {
                    ll.unpen <- sum(-integral + event * log(ft1 + 
                      expected))
                  }
                  else {
                    ll.unpen <- sum(-integral + event * pred1)
                  }
                  ll.pen <- ll.unpen - as.numeric(t(beta1) %*% 
                    S %*% beta1) * 0.5
                  if (is.nan(ll.pen)) {
                    ll.pen <- ll.pen.old - 1
                  }
              }
          }
          if (detail.beta) {
              cat("iter beta: ", k, "\n", "betaold= ", round(betaold, 
                  4), "\n", "beta= ", round(beta1, 4), "\n", "abs((beta-betaold)/betaold)= ", 
                  round(abs((beta1 - betaold)/betaold), 5), "\n", 
                  "ll.pen.old= ", round(ll.pen.old, 4), "\n", "ll.pen= ", 
                  round(ll.pen, 4), "\n", "ll.pen-ll.pen.old= ", 
                  round(ll.pen - ll.pen.old, 5), "\n", "\n")
          }
          k = k + 1
      }
      if (detail.beta) {
          cat("\n", "Beta optimization ok, ", k - 1, "iterations", 
              "\n", "--------------------------------------------------------------------------------------", 
              "\n")
      }
      list(beta = beta1, ll.unpen = ll.unpen, ll.pen = ll.pen, 
          haz.GL = haz.GL, iter.beta = k - 1)
  }
  <bytecode: 0x55faedbe45f0>
  <environment: namespace:survPen>
   --- function search by body ---
  Function NR.beta in namespace survPen has this body.
   ----------- END OF FAILURE REPORT -------------- 
  Fatal error: the condition has length > 1