Skip to content

Commit

Permalink
avoid falling back to environment, possible fix to #44
Browse files Browse the repository at this point in the history
  • Loading branch information
David Lawrence Miller committed Jun 14, 2021
1 parent 2ec0e07 commit 6fa2826
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions R/bootdht.R
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,17 @@ bootdht <- function(model,
our_resamples <- possible_resamples[c(resample_strata, resample_transects,
resample_obs)]

# process models
models <- lapply(models, function(model){
lpars <- as.list(model$call)
for(i in seq(2, length(lpars))){
if(is.symbol(model$call[[names(lpars)[i]]])){
model$call[[names(lpars)[i]]] <- eval(lpars[[i]])
}
}
model
})

# count failures
nbootfail <- 0
# function to do a single bootstrap iteration
Expand Down Expand Up @@ -190,7 +201,7 @@ bootdht <- function(model,
}

# fit that and update what's in models
models[[i]] <- try(suppressMessages(eval(df_call, parent.frame(n=3))),
models[[i]] <- try(suppressMessages(eval(df_call)),
silent=TRUE)

if(any(class(models[[i]]) == "try-error")){
Expand Down Expand Up @@ -288,7 +299,6 @@ bootdht <- function(model,
# they are data.frames and then rbind them all together
boot_ests <- do.call(rbind.data.frame, boot_ests)


cat("\n")

attr(boot_ests, "nboot") <- nboot
Expand Down

0 comments on commit 6fa2826

Please sign in to comment.