R/qpmR-package.R

Defines functions restore_rng fmt_num `%||%`

#' qpmR: Quarterly Projection Models for Monetary Policy Analysis
#'
#' Build, solve, and simulate the semi-structural quarterly projection
#' models (QPM) used in central-bank Forecasting and Policy Analysis
#' Systems (FPAS). Start with [qpm_template()] for the canonical
#' Berg-Karam-Laxton small open economy model, or declare your own model
#' with [qpm_model()]. Solve with [qpm_solve()], inspect dynamics with
#' [irf()], simulate with [stats::simulate()], and produce forecasts with
#' fan bands via [qpm_forecast()].
#'
#' @keywords internal
#' @useDynLib qpmR, .registration = TRUE
#' @importFrom Rcpp sourceCpp
"_PACKAGE"

# Canonical symbol separator used internally by the equation parser.
# "@" cannot appear in an R identifier, so rewritten symbols can never
# collide with user-declared names.
CANON_SEP <- "@"

`%||%` <- function(x, y) if (is.null(x)) y else x

fmt_num <- function(x, digits = 3) formatC(x, digits = digits, format = "fg")

# Bare shock names used non-standardly inside shocks() in shipped templates.
utils::globalVariables(c("eps_y", "eps_pi", "eps_i", "eps_q", "eps_qbar",
                         "eps_rbar", "eps_g", "eps_dy", "eps_ystar",
                         "eps_istar", "eps_pistar", "eps_prem",
                         "eps_pifood", "eps_fx", "eps_x", "e"))

# Restore the random number generator to the state captured before a
# user-supplied seed was set, so that a seeded call does not disturb the
# caller's random stream (the pattern used by stats:::simulate.lm).
restore_rng <- function(old) {
  if (is.null(old)) {
    if (exists(".Random.seed", envir = globalenv(), inherits = FALSE))
      rm(".Random.seed", envir = globalenv())
  } else {
    assign(".Random.seed", old, envir = globalenv())
  }
  invisible(NULL)
}

Try the qpmR package in your browser

Any scripts or data that you put into this service are public.

qpmR documentation built on Sept. 29, 2026, 5:10 p.m.