Skip to content

Commit eee2fb6

Browse files
committed
speedup parsing parameters
1 parent c7182bb commit eee2fb6

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

R/read_csv.R

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ read_cmdstan_csv <- function(files,
209209
fread_cmd <- paste0(grep_path, " -v '^#' ", output_file)
210210
} else {
211211
fread_cmd <- paste0("grep -v '^#' ", output_file)
212-
}
212+
}
213213
suppressWarnings(
214214
draws <- data.table::fread(
215215
cmd = fread_cmd,
@@ -412,21 +412,9 @@ read_csv_metadata <- function(csv_file) {
412412
if (!startsWith(line, "#") && is.null(csv_file_info[["model_params"]])) {
413413
# if no # at the start of line, the line is the CSV header
414414
all_names <- strsplit(line, ",")[[1]]
415-
csv_file_info[["sampler_diagnostics"]] <- c()
416-
csv_file_info[["model_params"]] <- c()
417-
for (x in all_names) {
418-
if (all(csv_file_info$algorithm != "fixed_param")) {
419-
if (endsWith(x, "__") && !(x %in% c("lp__", "log_p__", "log_g__"))) {
420-
csv_file_info[["sampler_diagnostics"]] <- c(csv_file_info[["sampler_diagnostics"]], x)
421-
} else {
422-
csv_file_info[["model_params"]] <- c(csv_file_info[["model_params"]], x)
423-
}
424-
} else {
425-
if (!endsWith(x, "__")) {
426-
csv_file_info[["model_params"]] <- c(csv_file_info[["model_params"]], x)
427-
}
428-
}
429-
}
415+
csv_file_info[["sampler_diagnostics"]] <- all_names[endsWith(all_names, "__")]
416+
csv_file_info[["sampler_diagnostics"]] <- csv_file_info[["sampler_diagnostics"]][!(csv_file_info[["sampler_diagnostics"]] %in% c("lp__", "log_p__", "log_g__"))]
417+
csv_file_info[["model_params"]] <- all_names[!(all_names %in% csv_file_info[["sampler_diagnostics"]])]
430418
} else {
431419
parse_key_val <- TRUE
432420
if (regexpr("# Diagonal elements of inverse mass matrix:", line, perl = TRUE) > 0

0 commit comments

Comments
 (0)