diff --git a/DESCRIPTION b/DESCRIPTION index ce09b826..7c3aa9e4 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: pomp Type: Package Title: Statistical Inference for Partially Observed Markov Processes -Version: 5.0.1.1 -Date: 2023-04-11 +Version: 5.0.1.2 +Date: 2023-04-13 Authors@R: c(person(given=c("Aaron","A."),family="King", role=c("aut","cre"),email="kingaa@umich.edu", comment=c(ORCID="0000-0001-6159-3207")), diff --git a/R/bake.R b/R/bake.R index 6e902bea..00a5020c 100644 --- a/R/bake.R +++ b/R/bake.R @@ -41,7 +41,7 @@ ##' @param dir Directory holding archive files; ##' by default, this is the current working directory. ##' This can also be set using the global option \code{pomp_archive_dir}. -##' This directory will be created if it does not exist. +##' If it does not exist, this directory will be created (with a message). ##' @param expr Expression to be evaluated. ##' @param seed,kind,normal.kind optional. ##' To set the state and of the RNG. @@ -150,6 +150,16 @@ update_bake_archive <- function (val, code, deps, file) { val } +create_path <- function (dir, file, mode = "0755") { + path <- file.path(as.character(dir[[1L]]),as.character(file[1L])) + dir <- dirname(path) + if (!dir.exists(dir)) { + pMess_("creating archive directory ",sQuote(dir),".") + dir.create(dir,recursive=TRUE,mode=mode) + } + path +} + ##' @rdname bake ##' @export bake <- function ( @@ -167,10 +177,7 @@ bake <- function ( ) info <- as.logical(info) timing <- as.logical(timing) - if (!dir.exists(dir)) { - dir.create(dir,recursive=TRUE,mode="0644") #nocov - } - file <- file.path(as.character(dir[[1L]]),as.character(file)) + file <- create_path(dir,file) reload <- file.exists(file) if (reload) { val <- readRDS(file) @@ -256,10 +263,7 @@ stew <- function ( ep="stew" ) info <- as.logical(info) - if (!dir.exists(dir)) { - dir.create(dir,recursive=TRUE,mode="0644") #nocov - } - file <- file.path(as.character(dir[[1L]]),as.character(file)) + file <- create_path(dir,file) reload <- file.exists(file) e <- new.env() if (reload) { diff --git a/inst/NEWS b/inst/NEWS index b38c5c81..f6379471 100644 --- a/inst/NEWS +++ b/inst/NEWS @@ -1,5 +1,10 @@ _N_e_w_s _f_o_r _p_a_c_k_a_g_e '_p_o_m_p' +_C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._0._1: + + • When the archive directory does not exist, ‘bake’ and ‘stew’ + now create it. + _C_h_a_n_g_e_s _i_n '_p_o_m_p' _v_e_r_s_i_o_n _5._0._0: • We no longer import from ‘plyr’. diff --git a/inst/NEWS.Rd b/inst/NEWS.Rd index 45cb05ad..40033e70 100644 --- a/inst/NEWS.Rd +++ b/inst/NEWS.Rd @@ -1,5 +1,10 @@ \name{NEWS} \title{News for package `pomp'} +\section{Changes in \pkg{pomp} version 5.0.1}{ + \itemize{ + \item When the archive directory does not exist, \code{bake} and \code{stew} now create it. + } +} \section{Changes in \pkg{pomp} version 5.0.0}{ \itemize{ \item We no longer import from \pkg{plyr}. diff --git a/man/bake.Rd b/man/bake.Rd index 7318d3ed..5873381b 100644 --- a/man/bake.Rd +++ b/man/bake.Rd @@ -73,7 +73,7 @@ This is returned as the \dQuote{system.time} attribute of the returned object.} \item{dir}{Directory holding archive files; by default, this is the current working directory. This can also be set using the global option \code{pomp_archive_dir}. -This directory will be created if it does not exist.} +If it does not exist, this directory will be created (with a message).} \item{envir}{the \code{\link[base]{environment}} in which \code{expr} is to be evaluated. May also be \code{NULL}, a list, a data frame, diff --git a/tests/bake.R b/tests/bake.R index 76cc85e3..f977e87a 100644 --- a/tests/bake.R +++ b/tests/bake.R @@ -128,3 +128,28 @@ stopifnot( identical(x,xx), identical(y,yy) ) + +capture.output( + { + bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x1 + bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x2 + bake(file="mary/tmp.rds",rnorm(5),dir=file.path(tempdir(),"results/bob")) -> x3 + op <- options(pomp_archive_dir=file.path(tempdir(),"results")) + bake(file="bob/mary/tmp.rds",rnorm(5)) -> x4 + bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x5 + options(op) + bake(file="results/results/bob/mary/tmp.rds",rnorm(5)) -> x6 + }, + type="message" +) -> out +stopifnot( + identical(x1,x2), + identical(x1,x3), + identical(x1,x4), + !identical(x1,x5), + identical(x5,x6), + length(out)==2, + grepl("^NOTE: creating archive directory",out), + grepl("results/bob/mary'.",out), + grepl("results/results/bob/mary'.",out[2]) +) diff --git a/tests/bake.Rout.save b/tests/bake.Rout.save index 43a96cc0..d3092f56 100644 --- a/tests/bake.Rout.save +++ b/tests/bake.Rout.save @@ -1,6 +1,6 @@ -R version 4.2.2 (2022-10-31) -- "Innocent and Trusting" -Copyright (C) 2022 The R Foundation for Statistical Computing +R version 4.2.3 (2023-03-15) -- "Shortstop Beagle" +Copyright (C) 2023 The R Foundation for Statistical Computing Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. @@ -177,3 +177,28 @@ NOTE: in 'stew': recomputing archive tmp2.rda. + identical(y,yy) + ) > +> capture.output( ++ { ++ bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x1 ++ bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x2 ++ bake(file="mary/tmp.rds",rnorm(5),dir=file.path(tempdir(),"results/bob")) -> x3 ++ op <- options(pomp_archive_dir=file.path(tempdir(),"results")) ++ bake(file="bob/mary/tmp.rds",rnorm(5)) -> x4 ++ bake(file="results/bob/mary/tmp.rds",rnorm(5)) -> x5 ++ options(op) ++ bake(file="results/results/bob/mary/tmp.rds",rnorm(5)) -> x6 ++ }, ++ type="message" ++ ) -> out +> stopifnot( ++ identical(x1,x2), ++ identical(x1,x3), ++ identical(x1,x4), ++ !identical(x1,x5), ++ identical(x5,x6), ++ length(out)==2, ++ grepl("^NOTE: creating archive directory",out), ++ grepl("results/bob/mary'.",out), ++ grepl("results/results/bob/mary'.",out[2]) ++ ) +>