diff --git a/DESCRIPTION b/DESCRIPTION index 151f6fac3..ac155bf6e 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -48,6 +48,7 @@ Imports: rlang (>= 0.4.7) Suggests: bayesplot, + fs, ggplot2, knitr (>= 1.37), loo (>= 2.0.0), diff --git a/R/csv.R b/R/csv.R index 4e585fa6d..8ac913937 100644 --- a/R/csv.R +++ b/R/csv.R @@ -254,7 +254,7 @@ read_cmdstan_csv <- function(files, "\"" ) } else { - fread_cmd <- paste0("grep -v '^#' --color=never '", output_file, "'") + fread_cmd <- paste0("grep -v '^#' --color=never '", path.expand(output_file), "'") } if (length(sampler_diagnostics) > 0) { post_warmup_sd_id <- length(post_warmup_sampler_diagnostics) + 1 diff --git a/tests/testthat/test-csv.R b/tests/testthat/test-csv.R index 6dc331fee..dc678a6bc 100644 --- a/tests/testthat/test-csv.R +++ b/tests/testthat/test-csv.R @@ -888,3 +888,11 @@ test_that("read_cmdstan_csv works if no variables are specified", { read_cmdstan_csv(fit_bernoulli_thin_1$output_files(), variables = "", sampler_diagnostics = "") ) }) + +test_that("read_cmdstan_csv() works with tilde expansion", { + skip_if(os_is_windows()) + full_path <- test_path("resources", "csv", "model1-1-warmup.csv") + expect_no_error(read_cmdstan_csv(full_path)) + tildified_path <- file.path("~", fs::path_rel(full_path, "~")) + expect_no_error(read_cmdstan_csv(tildified_path)) +})