Skip to content

Commit

Permalink
remove option for progress file in ebase, can crash jags unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
fawda123 committed Jun 5, 2024
1 parent e7f1956 commit a7a01a7
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 24 deletions.
14 changes: 1 addition & 13 deletions R/ebase.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#' @param n.burnin number of MCMC chains to delete, passed to \code{\link[R2jags]{jags}}
#' @param n.chains number of MCMC chains to run, passed to \code{\link[R2jags]{jags}}
#' @param n.thin number of nth iterations to save for each chain, passed to \code{\link[R2jags]{jags}}
#' @param progress character string of path where progress is saved to as 'log.txt', use \code{NULL} to suppress (default)
#' @param model_file \code{NULL} to use the model file included with the package or a path to a model text file can be used
#'
#' @export
Expand Down Expand Up @@ -71,7 +70,7 @@
#' # run ebase, use more chains and iterations for a better fit, update.chains as T
#' ebase(dat, interval = 900, Z = 1.85, n.chains = 2, n.iter = 50,
#' update.chains = FALSE)
ebase <- function(dat, Z, interval, ndays = 1, aprior = c(4, 2), rprior = c(300, 150), bprior = c(0.251, 0.125), bmax = 0.502, nogas = FALSE, doave = TRUE, maxinterp = 43200 / interval, n.iter = 10000, update.chains = TRUE, n.burnin = n.iter*0.5, n.chains = 3, n.thin = 10, progress = NULL, model_file = NULL){
ebase <- function(dat, Z, interval, ndays = 1, aprior = c(4, 2), rprior = c(300, 150), bprior = c(0.251, 0.125), bmax = 0.502, nogas = FALSE, doave = TRUE, maxinterp = 43200 / interval, n.iter = 10000, update.chains = TRUE, n.burnin = n.iter*0.5, n.chains = 3, n.thin = 10, model_file = NULL){

# prep data
dat <- ebase_prep(dat, Z = Z, interval = interval, ndays = ndays)
Expand All @@ -94,23 +93,12 @@ ebase <- function(dat, Z, interval, ndays = 1, aprior = c(4, 2), rprior = c(300,
if(nogas)
bprior <- c(0, 1e-8)

# setup log file
strt <- Sys.time()

# iterate through each date to estimate metabolism ------------------------

# process
output <- foreach(i = grps, .packages = c('R2jags', 'rjags', 'dplyr'), .export = c('nstepd', 'metab_update', 'interval', 'aprior', 'rprior', 'bprior', 'bmax')
) %dopar% {

if(!is.null(progress)){
sink(file.path(progress, 'log.txt'))
cat('Log entry time', as.character(Sys.time()), '\n')
cat('Group ', which(i == grps), ' of ', length(grps), '\n')
print(Sys.time() - strt)
sink()
}

dat.sub <- dat[dat$grp == i,]

# Define vectors for JAGS
Expand Down
3 changes: 0 additions & 3 deletions man/ebase.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions tests/testthat/test-ebase.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
test_that("Checking ebase output, doave as F", {

# temp dir for log
tmpdir <- tempdir()

# check format
result <- EBASE::ebase(dat, interval = 900, Z = 1.85, n.chains = 2, doave = F,
n.iter = 100, progress = tmpdir,
n.iter = 100,
model_file = system.file("ebase_model.txt", package = "EBASE"))

expect_s3_class(result, 'data.frame')
Expand All @@ -16,9 +13,6 @@ test_that("Checking ebase output, doave as F", {
"DO_modhi", "dDO", "converge", "rsq", "a", "alo", "ahi", "b", "blo",
"bhi", "P", "Plo", "Phi", "R", "Rlo", "Rhi", "D", "Dlo", "Dhi"))

# check log location
expect_true(file.exists(file.path(tmpdir, "log.txt")))

})

test_that("Checking ebase output, no gas exchange", {
Expand Down
2 changes: 1 addition & 1 deletion vignettes/EBASE.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ head(dat)
Also note that any "dangling" observations at the start or end of the time series that do not include an entire day are removed from the input data prior to estimating metabolism. A warning is returned if these observations are found and removed.

```{r}
res <- ebase(dat, interval = 900, Z = 1.85, n.chains = 2, nogas = T)
res <- ebase(dat, interval = 900, Z = 1.85, n.chains = 2)
head(res)
```

Expand Down

0 comments on commit a7a01a7

Please sign in to comment.