From dc3887b896f8651b65bc7488bddb3ac46e009938 Mon Sep 17 00:00:00 2001 From: Jim Thorson <50178738+James-Thorson-NOAA@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:35:27 -0700 Subject: [PATCH 1/4] Fix #19 --- DESCRIPTION | 4 ++-- NAMESPACE | 1 - NEWS.md | 5 +++++ R/utils.R | 61 ++++++++++++++++++++++++++--------------------------- R/zzz.R | 2 +- 5 files changed, 38 insertions(+), 35 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index b538b45..eb08a06 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: dsem Type: Package Title: Fit Dynamic Structural Equation Models -Version: 1.2.0 -Date: 2024-03-29 +Version: 1.2.1 +Date: 2024-04-02 Authors@R: c(person(given = "James", family = "Thorson", diff --git a/NAMESPACE b/NAMESPACE index 436e121..c094211 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -11,7 +11,6 @@ S3method(vcov,dsem) export(TMBAIC) export(as_fitted_DAG) export(as_sem) -export(checkDepPackageVersion) export(classify_variables) export(dsem) export(dsem_control) diff --git a/NEWS.md b/NEWS.md index ed27bea..9350012 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +# dsem 1.2.1 + +* removing `checkDepPackageVersion(dep_pkg="Matrix", this_pkg="TMB")` from `.onLoad()` + as requested by K. Kristensen + # dsem 1.2.0 * Adding option to specify covariance via argument `covs` diff --git a/R/utils.R b/R/utils.R index 031eb8d..18dbd49 100644 --- a/R/utils.R +++ b/R/utils.R @@ -6,37 +6,36 @@ #' @param warn give warning? #' @return logical: TRUE if the binary versions match #' @importFrom utils packageVersion -#' @export -checkDepPackageVersion <- function(dep_pkg = "TMB", - this_pkg = "dsem", - write_file = FALSE, - warn = TRUE) { - cur_dep_version <- as.character(packageVersion(dep_pkg)) - fn <- sprintf("%s-version", dep_pkg) - if (write_file) { - cat(sprintf("current %s version=%s: writing file\n", dep_pkg, cur_dep_version)) - writeLines(cur_dep_version, con = fn) - return(cur_dep_version) - } - fn <- system.file(fn, package=this_pkg) - built_dep_version <- scan(file=fn, what=character(), quiet=TRUE) - result_ok <- identical(built_dep_version, cur_dep_version) - if(warn && !result_ok) { - warning( - "Package version inconsistency detected.\n", - sprintf("%s was built with %s version %s", - this_pkg, dep_pkg, built_dep_version), - "\n", - sprintf("Current %s version is %s", - dep_pkg, cur_dep_version), - "\n", - sprintf("Please re-install %s from source ", this_pkg), - "or restore original ", - sQuote(dep_pkg), " package (see '?reinstalling' for more information)" - ) - } - return(result_ok) -} +#checkDepPackageVersion <- function(dep_pkg = "TMB", +# this_pkg = "dsem", +# write_file = FALSE, +# warn = TRUE) { +# cur_dep_version <- as.character(packageVersion(dep_pkg)) +# fn <- sprintf("%s-version", dep_pkg) +# if (write_file) { +# cat(sprintf("current %s version=%s: writing file\n", dep_pkg, cur_dep_version)) +# writeLines(cur_dep_version, con = fn) +# return(cur_dep_version) +# } +# fn <- system.file(fn, package=this_pkg) +# built_dep_version <- scan(file=fn, what=character(), quiet=TRUE) +# result_ok <- identical(built_dep_version, cur_dep_version) +# if(warn && !result_ok) { +# warning( +# "Package version inconsistency detected.\n", +# sprintf("%s was built with %s version %s", +# this_pkg, dep_pkg, built_dep_version), +# "\n", +# sprintf("Current %s version is %s", +# dep_pkg, cur_dep_version), +# "\n", +# sprintf("Please re-install %s from source ", this_pkg), +# "or restore original ", +# sQuote(dep_pkg), " package (see '?reinstalling' for more information)" +# ) +# } +# return(result_ok) +#} #' @name reinstalling #' @rdname reinstalling diff --git a/R/zzz.R b/R/zzz.R index 9b2a058..9ec976c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -4,7 +4,7 @@ # See: https://mail.google.com/mail/u/0/#inbox/QgrcJHsNjpqZNGJhNMVHcfGFDLLMfrvqqHl .onLoad <- function(libname, pkgname) { #checkDepPackageVersion(dep_pkg="TMB", this_pkg="dsem") - checkDepPackageVersion(dep_pkg="Matrix", this_pkg="TMB") + #checkDepPackageVersion(dep_pkg="Matrix", this_pkg="TMB") } .onUnload <- function(libpath) { From 2d7274af824d301f05ad5a866ad8a89851ca8524 Mon Sep 17 00:00:00 2001 From: Jim Thorson <50178738+James-Thorson-NOAA@users.noreply.github.com> Date: Tue, 2 Apr 2024 08:59:39 -0700 Subject: [PATCH 2/4] further fix --- NAMESPACE | 1 - R/utils.R | 80 ----------------------------------- man/checkDepPackageVersion.Rd | 28 ------------ man/reinstalling.Rd | 44 ------------------- 4 files changed, 153 deletions(-) delete mode 100644 R/utils.R delete mode 100644 man/checkDepPackageVersion.Rd delete mode 100644 man/reinstalling.Rd diff --git a/NAMESPACE b/NAMESPACE index c094211..aedd77b 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -41,5 +41,4 @@ importFrom(stats,sd) importFrom(stats,simulate) importFrom(stats,time) importFrom(stats,vcov) -importFrom(utils,packageVersion) useDynLib(dsem, .registration = TRUE) diff --git a/R/utils.R b/R/utils.R deleted file mode 100644 index 18dbd49..0000000 --- a/R/utils.R +++ /dev/null @@ -1,80 +0,0 @@ -#' @title Check for version mismatch in dependent binary packages -#' @description Copied from glmmTMB with permission -#' @param dep_pkg upstream package -#' @param this_pkg downstream package -#' @param write_file (logical) write version file and quit? -#' @param warn give warning? -#' @return logical: TRUE if the binary versions match -#' @importFrom utils packageVersion -#checkDepPackageVersion <- function(dep_pkg = "TMB", -# this_pkg = "dsem", -# write_file = FALSE, -# warn = TRUE) { -# cur_dep_version <- as.character(packageVersion(dep_pkg)) -# fn <- sprintf("%s-version", dep_pkg) -# if (write_file) { -# cat(sprintf("current %s version=%s: writing file\n", dep_pkg, cur_dep_version)) -# writeLines(cur_dep_version, con = fn) -# return(cur_dep_version) -# } -# fn <- system.file(fn, package=this_pkg) -# built_dep_version <- scan(file=fn, what=character(), quiet=TRUE) -# result_ok <- identical(built_dep_version, cur_dep_version) -# if(warn && !result_ok) { -# warning( -# "Package version inconsistency detected.\n", -# sprintf("%s was built with %s version %s", -# this_pkg, dep_pkg, built_dep_version), -# "\n", -# sprintf("Current %s version is %s", -# dep_pkg, cur_dep_version), -# "\n", -# sprintf("Please re-install %s from source ", this_pkg), -# "or restore original ", -# sQuote(dep_pkg), " package (see '?reinstalling' for more information)" -# ) -# } -# return(result_ok) -#} - -#' @name reinstalling -#' @rdname reinstalling -#' @title Reinstalling binary dependencies -#' -#' @description The \code{dsem} package depends on several upstream packages, which it -#' uses in a way that depends heavily on their internal (binary) structure. -#' Sometimes, therefore, installing an update to one of these packages will -#' require that you re-install a \emph{binary-compatible} version of \code{dsem}, -#' i.e. a version that has been compiled with the updated version of the upstream -#' package. -#' \itemize{ -#' \item If you have development tools (compilers etc.) installed, you -#' should be able to re-install a binary-compatible version of the package by running -#' \code{install.packages("dsem", type="source")}. If you want to install -#' the development version of \code{dsem} instead, you can use -#' \code{remotes::install_github("James-Thorson-NOAA/dsem")}. -#' (On Windows, you can install development tools following the instructions at -#' \url{https://cran.r-project.org/bin/windows/Rtools/}; on MacOS, see -#' \url{https://mac.r-project.org/tools/}.) -#' -#' \item If you do \emph{not} have development tools and can't/don't want to -#' install them (and so can't install packages with compiled code from source), -#' you can revert the upstream package(s) to their previous binary version. For example, using the -#' \code{checkpoint} package: -#' \preformatted{ -#' ## load (installing if necessary) the checkpoint package -#' while (!require("checkpoint")) install.packages("checkpoint") -#' ## retrieve build date of installed version of dsem -#' bd <- as.character(asDateBuilt( -#' packageDescription("dsem",fields="Built"))) -#' oldrepo <- getOption("repos") -#' use_mran_snapshot(bd) ## was setSnapshot() pre-checkpoint v1.0.0 -#' install.packages("TMB") -#' options(repos=oldrepo) ## restore original repo -#' } -#' A similar recipe (substituting \code{Matrix} for \code{TMB} and \code{TMB} for \code{dsem}) -#' can be used if you get warnings about an incompatibility between \code{TMB} and \code{Matrix}. -#' } -#' @details Copied from glmmTMB with permission -NULL - diff --git a/man/checkDepPackageVersion.Rd b/man/checkDepPackageVersion.Rd deleted file mode 100644 index 1a4a61b..0000000 --- a/man/checkDepPackageVersion.Rd +++ /dev/null @@ -1,28 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{checkDepPackageVersion} -\alias{checkDepPackageVersion} -\title{Check for version mismatch in dependent binary packages} -\usage{ -checkDepPackageVersion( - dep_pkg = "TMB", - this_pkg = "dsem", - write_file = FALSE, - warn = TRUE -) -} -\arguments{ -\item{dep_pkg}{upstream package} - -\item{this_pkg}{downstream package} - -\item{write_file}{(logical) write version file and quit?} - -\item{warn}{give warning?} -} -\value{ -logical: TRUE if the binary versions match -} -\description{ -Copied from glmmTMB with permission -} diff --git a/man/reinstalling.Rd b/man/reinstalling.Rd deleted file mode 100644 index 9e2ad3a..0000000 --- a/man/reinstalling.Rd +++ /dev/null @@ -1,44 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/utils.R -\name{reinstalling} -\alias{reinstalling} -\title{Reinstalling binary dependencies} -\description{ -The \code{dsem} package depends on several upstream packages, which it -uses in a way that depends heavily on their internal (binary) structure. -Sometimes, therefore, installing an update to one of these packages will -require that you re-install a \emph{binary-compatible} version of \code{dsem}, -i.e. a version that has been compiled with the updated version of the upstream -package. -\itemize{ -\item If you have development tools (compilers etc.) installed, you -should be able to re-install a binary-compatible version of the package by running -\code{install.packages("dsem", type="source")}. If you want to install -the development version of \code{dsem} instead, you can use -\code{remotes::install_github("James-Thorson-NOAA/dsem")}. -(On Windows, you can install development tools following the instructions at -\url{https://cran.r-project.org/bin/windows/Rtools/}; on MacOS, see -\url{https://mac.r-project.org/tools/}.) - -\item If you do \emph{not} have development tools and can't/don't want to -install them (and so can't install packages with compiled code from source), -you can revert the upstream package(s) to their previous binary version. For example, using the -\code{checkpoint} package: -\preformatted{ -## load (installing if necessary) the checkpoint package -while (!require("checkpoint")) install.packages("checkpoint") -## retrieve build date of installed version of dsem -bd <- as.character(asDateBuilt( - packageDescription("dsem",fields="Built"))) -oldrepo <- getOption("repos") -use_mran_snapshot(bd) ## was setSnapshot() pre-checkpoint v1.0.0 -install.packages("TMB") -options(repos=oldrepo) ## restore original repo -} -A similar recipe (substituting \code{Matrix} for \code{TMB} and \code{TMB} for \code{dsem}) -can be used if you get warnings about an incompatibility between \code{TMB} and \code{Matrix}. -} -} -\details{ -Copied from glmmTMB with permission -} From b1c86bb6df1d87d2322dc26f93ae22c5e2139b83 Mon Sep 17 00:00:00 2001 From: Jim Thorson <50178738+James-Thorson-NOAA@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:05:52 -0700 Subject: [PATCH 3/4] small update --- R/dsem.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/dsem.R b/R/dsem.R index 652a07b..b3c9739 100644 --- a/R/dsem.R +++ b/R/dsem.R @@ -873,9 +873,10 @@ logLik.dsem <- function(object, ...) { as_fitted_DAG <- function( fit, lag = 0, - what = "Estimate", + what = c("Estimate","Std_Error","p_value"), direction = 1 ){ + what = match.arg(what) coefs = summary( fit ) coefs = coefs[ which(coefs[,2]==lag), ] coefs = coefs[ which(coefs[,'direction'] %in% direction), ] From 633f028ce402ab216ff3e9efae2ace6c898e1002 Mon Sep 17 00:00:00 2001 From: Jim Thorson <50178738+James-Thorson-NOAA@users.noreply.github.com> Date: Mon, 15 Apr 2024 10:21:27 -0700 Subject: [PATCH 4/4] Update as_fitted_DAG.Rd --- man/as_fitted_DAG.Rd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/man/as_fitted_DAG.Rd b/man/as_fitted_DAG.Rd index a542b44..ea3109b 100644 --- a/man/as_fitted_DAG.Rd +++ b/man/as_fitted_DAG.Rd @@ -4,7 +4,12 @@ \alias{as_fitted_DAG} \title{Convert output from package dsem to phylopath} \usage{ -as_fitted_DAG(fit, lag = 0, what = "Estimate", direction = 1) +as_fitted_DAG( + fit, + lag = 0, + what = c("Estimate", "Std_Error", "p_value"), + direction = 1 +) } \arguments{ \item{fit}{Output from \code{\link{dsem}}}