From 3f5d32e9448bedcd48a18219d371c34f2194e40c Mon Sep 17 00:00:00 2001 From: Luna Fazio Date: Thu, 9 Nov 2023 02:53:00 +0100 Subject: [PATCH 1/2] Special casing for lp_approx__ - Replace lp_approx__ with log_g__ - Assign then return stanfit object instead of implicit return --- R/backends.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/backends.R b/R/backends.R index bcfb201df..c03b2044d 100644 --- a/R/backends.R +++ b/R/backends.R @@ -298,6 +298,7 @@ fit_model <- function(model, backend, ...) { variables <- repair_variable_names(metadata$metadata$variables) variables <- unique(sub("\\[.+", "", variables)) variables <- setdiff(variables, exclude) + variables <- ifelse(variables == "lp_approx__", "log_g__", variables) # transform into stanfit object for consistent output structure out <- read_csv_as_stanfit(out$output_files(), variables = variables) out <- repair_stanfit(out) @@ -941,7 +942,7 @@ read_csv_as_stanfit <- function(files, variables = NULL, sdate <- do.call(max, lapply(files, function(csv) file.info(csv)$mtime)) sdate <- format(sdate, "%a %b %d %X %Y") - new( + out <- new( "stanfit", model_name = model_name, model_pars = svars, @@ -954,4 +955,5 @@ read_csv_as_stanfit <- function(files, variables = NULL, date = sdate, # not the time of sampling .MISC = new.env(parent = emptyenv()) ) + return(out) } From 1ce56d0ecfd008ff7306fc6dd560ab6c1966eaa0 Mon Sep 17 00:00:00 2001 From: Luna Fazio Date: Thu, 9 Nov 2023 15:25:46 +0100 Subject: [PATCH 2/2] Explain temp fix, clean code up Add comment to temp fix for cmdstanr Removed stanfit explicit return as it turns out it wasn't needed --- R/backends.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/backends.R b/R/backends.R index c03b2044d..dcfc512e7 100644 --- a/R/backends.R +++ b/R/backends.R @@ -298,6 +298,7 @@ fit_model <- function(model, backend, ...) { variables <- repair_variable_names(metadata$metadata$variables) variables <- unique(sub("\\[.+", "", variables)) variables <- setdiff(variables, exclude) + # temp fix for cmdstanr not recognizing the variable names it produces #1473 variables <- ifelse(variables == "lp_approx__", "log_g__", variables) # transform into stanfit object for consistent output structure out <- read_csv_as_stanfit(out$output_files(), variables = variables) @@ -942,7 +943,7 @@ read_csv_as_stanfit <- function(files, variables = NULL, sdate <- do.call(max, lapply(files, function(csv) file.info(csv)$mtime)) sdate <- format(sdate, "%a %b %d %X %Y") - out <- new( + new( "stanfit", model_name = model_name, model_pars = svars, @@ -955,5 +956,4 @@ read_csv_as_stanfit <- function(files, variables = NULL, date = sdate, # not the time of sampling .MISC = new.env(parent = emptyenv()) ) - return(out) }