match_params: Find matching node names

View source: R/match_params.R

match_paramsR Documentation

Find matching node names

Description

Returns all the node names stored in a mcmc.list object that match a provided string.

Usage

match_params(post, params, type = "base_index", auto_escape = TRUE)

Arguments

post

A mcmc.list object.

params

A vector of regular expressions specifying the nodes to match. Accepts multi-element vectors to match more than one node at a time. See examples and vignette("pattern-matching") for more details.

type

Format of returned matches; only two options are accepted:

  • type = "base_only" to return only the unique node names (without indices).

  • type = "base_index" (the default) to return the node names with indices included.

auto_escape

Automatically escape "[" and "]" characters for pattern matching? FALSE will treat "[" and "]" as special regular expression characters (unless explicitly escaped by user), TRUE will treat these symbols as plain text to be matched. It is generally recommended to keep this as TRUE (the default), unless you are performing complex regex searches that require the "[" and "]" symbols to be special characters.

Details

This function is called as one of the first steps in many of the more downstream functions in this package. It is thus fairly important to get used to how the regular expressions work. This function can be used directly to hone in on the correct regular expression. See the examples below.

Value

A character vector with all node names in post that match params, formatted as requested by type.. If no matches are found, an error will be returned with the base node names found in post to help the next try.

Examples

# load example mcmc.list
data(cjs)

# these produce same output b/c of regex pattern matching
match_params(cjs, params = c("b0", "b1"))
match_params(cjs, params = c("b"))

# return only base names, not indices as well
match_params(cjs, params = "b", type = "base_only")

# force a match to start with B
match_params(cjs, "^B")

# force a match to end with 0
match_params(cjs, "0$")

# use a wild card to get b0[3] and b1[3]
match_params(cjs, "b.[3]")

# repeat a wild card
match_params(cjs, "s.+0")

# turn off auto escape to use [] in regex syntax rather than matching them as text
match_params(cjs, params = "[:digit:]$", auto_escape = FALSE)

# pass a dot to match all (same as get_params)
match_params(cjs, ".")

postpack documentation built on Dec. 28, 2022, 1:23 a.m.