aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Kellner <ken@kenkellner.com>2020-10-07 08:06:47 -0400
committerKen Kellner <ken@kenkellner.com>2020-10-07 08:11:22 -0400
commita8d827a121aa7fb7e761df8aaca4a2052a1fece1 (patch)
tree4c04a128eedd352e4ae432ecc43ccfa150cff1e5
parent9e793a6615d645bc3147669e529f4a699f874ab2 (diff)
Allow plotting subsets of parameters, fix version issue
-rw-r--r--DESCRIPTION4
-rw-r--r--R/get_plot_info.R21
2 files changed, 23 insertions, 2 deletions
diff --git a/DESCRIPTION b/DESCRIPTION
index d804a1c..3a84308 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -1,6 +1,6 @@
Package: jagsUI
-Version: 1.5.1.9000
-Date: 2020-10-06
+Version: 1.5.1.9100
+Date: 2020-10-07
Title: A Wrapper Around 'rjags' to Streamline 'JAGS' Analyses
Author: Ken Kellner <contact@kenkellner.com>
Maintainer: Ken Kellner <contact@kenkellner.com>
diff --git a/R/get_plot_info.R b/R/get_plot_info.R
index edc6c7a..86d4389 100644
--- a/R/get_plot_info.R
+++ b/R/get_plot_info.R
@@ -5,6 +5,9 @@ get_plot_info <- function(x, parameters, per_plot, ask, Rhat_min=NULL){
#Expand non-scalar parameters and check they exist
all_params <- param_names(x$samples)
if(!is.null(parameters)){
+ #Expand bracketed parameter names
+ parameters <- expand_params(parameters)
+ #Check parameters are in output
parameters <- match_params(parameters, all_params)
if(is.null(parameters)){
stop("None of the provided parameters were found in the output")
@@ -33,3 +36,21 @@ get_plot_info <- function(x, parameters, per_plot, ask, Rhat_min=NULL){
list(params=parameters, new_par=new_par, per_plot=per_plot)
}
+
+
+has_brackets <- function(x){
+ grepl("\\[.*\\]", x)
+}
+
+expand_brackets <- function(x){
+ if(!has_brackets(x)) return(x)
+
+ pname <- strsplit(x, "\\[")[[1]][1]
+ rng <- gsub(paste0(pname,"|\\[|\\]"), "", x)
+ rng <- eval(parse(text=rng))
+ paste0(pname, "[",rng,"]")
+}
+
+expand_params <- function(params){
+ unlist(lapply(params, expand_brackets))
+}