From c03fa5d4e57033869cb437c1154da31abd96fc50 Mon Sep 17 00:00:00 2001 From: Johannes Ranke Date: Fri, 14 Oct 2022 16:20:42 +0200 Subject: update method for mhmkin objects, clarify comment --- R/mhmkin.R | 23 +++++++++++++++++++++++ R/saem.R | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'R') diff --git a/R/mhmkin.R b/R/mhmkin.R index 2cf9ba06..2df01f0c 100644 --- a/R/mhmkin.R +++ b/R/mhmkin.R @@ -203,3 +203,26 @@ BIC.mhmkin <- function(object, ...) { dimnames(res) <- dimnames(object) return(res) } + +#' @export +update.mhmkin <- function(object, ..., evaluate = TRUE) { + call <- attr(object, "call") + + update_arguments <- match.call(expand.dots = FALSE)$... + + if (length(update_arguments) > 0) { + update_arguments_in_call <- !is.na(match(names(update_arguments), names(call))) + } + + for (a in names(update_arguments)[update_arguments_in_call]) { + call[[a]] <- update_arguments[[a]] + } + + update_arguments_not_in_call <- !update_arguments_in_call + if(any(update_arguments_not_in_call)) { + call <- c(as.list(call), update_arguments[update_arguments_not_in_call]) + call <- as.call(call) + } + if(evaluate) eval(call, parent.frame()) + else call +} diff --git a/R/saem.R b/R/saem.R index 99712c92..5256f6b5 100644 --- a/R/saem.R +++ b/R/saem.R @@ -635,8 +635,8 @@ logLik.saem.mmkin <- function(object, ...) return(logLik(object$so)) update.saem.mmkin <- function(object, ..., evaluate = TRUE) { call <- object$call # For some reason we get saem.mmkin in the call when using mhmkin - # so we need to fix this in order to avoid exporting saem.mmkin - # in addition to the S3 method + # so we need to fix this so we do not have to export saem.mmkin in + # addition to the S3 method call[[1]] <- saem update_arguments <- match.call(expand.dots = FALSE)$... -- cgit v1.2.1