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

> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: batch.estimation
> ### Title: Two stage estimation, a pilot estimate of mixing alpha and a
> ###   following importance sampling, with or without control variates
> ### Aliases: batch.estimation
> 
> ### ** Examples
> 
> library(optismixture)
> seed <- 1
> p <- 5
> rho <- 1/2
> gamma <- 2.4
> sigma.dvar <- function(rho, p){
+    sigma <- matrix(0, p, p)
+    for(i in 1:(p-1)){
+        for(j in (i+1):p){
+            sigma[i,j] <- rho^(abs(i-j))
+        }
+    }
+    sigma <- sigma + t(sigma)
+    diag(sigma) <- 1
+    return(sigma)
+ }
> sigma <- sigma.dvar(rho, p)
> batch.size <- c(10^4, 1002)
> j.vec <- 2^-(seq(1,5,1))
> eps.status <- 1
> eps.safe <- 0.1
> ## initialization and construct derived parameters
> mu <- rep(0, p)
> x0 <- matrix(1, 1, p)
> x0.mat <- rbind(rep(1,p), rep(-1, p))
> j.mat <- data.frame(centerid = rep(1:dim(x0.mat)[1], each = length(j.vec)),
+                     variance = rep(j.vec, 2))
> J <- dim(j.mat)[1] + 1
> eps <- rep(0.1/J, J)
> mixture.param <- list(x0 = x0, x0.mat = x0.mat, p = p,
+ sigma = sigma, gamma = gamma, j.mat = j.mat, J = J)
> f <- function(x, j, mixture.param){
+     f1 <- function(x, mixture.param){
+         x0 <- mixture.param$x0
+         gamma <- mixture.param$gamma
+         return(sum((x - x0)^2)^(-gamma/2))
+     }
+     return(apply(x, 1, f1, mixture.param))
+ }
> dq <- function(x, j, mixture.param){
+     centerid <- mixture.param$j.mat[j, 1]
+     j.param <- mixture.param$j.mat[j, 2]
+     return(mvtnorm::dmvnorm(x, mixture.param$x0.mat[centerid,], j.param*diag(mixture.param$p)))
+ }
> dp <- function(x, mixture.param){
+     return(mvtnorm::dmvnorm(x, rep(0, mixture.param$p), mixture.param$sigma))
+ }
> rq <- function(n, j, mixture.param){
+     centerid <- mixture.param$j.mat[j, 1]
+     j.param <- mixture.param$j.mat[j,2]
+     return(mvtnorm::rmvnorm(n, mixture.param$x0.mat[centerid, ], j.param*diag(mixture.param$p)))
+ }
> rp <- function(n, mixture.param){
+     mu <- rep(0, mixture.param$p)
+     sigma <- mixture.param$sigma
+     return(mvtnorm::rmvnorm(n, mu, sigma))
+ }
> a <- batch.estimation(seed, batch.size, mixture.param, eps, cv = FALSE,
+ fname = "f", rpname = "rp", rqname = "rq", dpname = "dp", dqname = "dq")
 ----------- FAILURE REPORT -------------- 
 --- failure: the condition has length > 1 ---
 --- srcref --- 
: 
 --- package (from environment) --- 
optismixture
 --- call from context --- 
dampednewton(alpha, rho, reltol = reltol)
 --- call from argument --- 
if (class(newtonstep) == "try-error") {
    if (isTRUE(all.equal(vals$g, rep(0, length(vals$g))))) {
        solstatus <- "exact"
        break
    }
    else {
        print("returning inexact solution")
        solstatus <- "inexact"
        break
    }
}
 --- R stacktrace ---
where 1: dampednewton(alpha, rho, reltol = reltol)
where 2: penoptpersp.alpha.only(y = opt.input$Y[get.index.b(batch.size, 
    b), ], z = as.matrix(opt.input$Z[get.index.b(batch.size, 
    b), ]), a0 = alpha.opt, eps = eps, reltol = opt.param$reltol, 
    relerr = opt.param$relerr, rho0 = opt.param$rho0, maxin = opt.param$maxin, 
    maxout = opt.param$maxout)
where 3: batch.estimation(seed, batch.size, mixture.param, eps, cv = FALSE, 
    fname = "f", rpname = "rp", rqname = "rq", dpname = "dp", 
    dqname = "dq")

 --- value of length: 2 type: logical ---
[1] FALSE FALSE
 --- function from context --- 
function (alpha, rho, reltol) 
{
    done = FALSE
    inct <- 0
    oldf <- -Inf
    while (1) {
        vals = fgH(alpha, rho, do = 3)
        if (identical(oldf, vals$f)) {
            solstatus <- "exact"
            break
        }
        oldf <- vals$f
        newtonstep = try(-svdsolve(vals$H, vals$g), silent = TRUE)
        if (class(newtonstep) == "try-error") {
            if (isTRUE(all.equal(vals$g, rep(0, length(vals$g))))) {
                solstatus <- "exact"
                break
            }
            else {
                print("returning inexact solution")
                solstatus <- "inexact"
                break
            }
        }
        newtonstep <- drop(newtonstep)
        decrement = -(vals$g %*% newtonstep)[1, 1]/2
        reldecrement = decrement/vals$f
        if (reldecrement <= reltol) {
            solstatus <- "exact"
            break
        }
        tval = linesearch(alpha, rho, newtonstep, vals$f, vals$g)
        alpha = alpha + tval * newtonstep
        inct = inct + 1
        if (inct >= maxin) {
            print("Reaching maximum inner iterations")
            solstatus <- "semiexact"
            print(paste("decrement", decrement))
            print(paste("vals$f", vals$f))
            break
        }
    }
    list(alpha = alpha, solstatus = solstatus, inct = inct)
}
<bytecode: 0x5582cdbc0060>
<environment: 0x5582cc73b7c8>
 --- function search by body ---
 ----------- END OF FAILURE REPORT -------------- 
Error in if (class(newtonstep) == "try-error") { : 
  the condition has length > 1
Calls: batch.estimation -> penoptpersp.alpha.only -> dampednewton
Execution halted