R/drop-parameters.R

Defines functions drop_pars.tmb_code

#' @export
drop_pars.tmb_code <- function(x, pars = character(0), ...) {
  chk_vector(pars, "")
  chk_unique(pars)

  if (!length(pars)) {
    return(x)
  }

  template <- template(x)

  for (parameter in pars) {
    if (!str_detect(template, str_c("PARAMETER[(]", parameter, "[)]"))) {
      error("fixed scalar parameter '", parameter, "' not found in model code")
    }
    template %<>% str_replace(
      str_c("PARAMETER[(]", parameter, "[)]"),
      str_c("Type ", parameter, " = 0.0")
    )
  }

  x$template <- template
  x
}
poissonconsulting/tmbr documentation built on Aug. 12, 2024, 6:33 p.m.