rstan icon indicating copy to clipboard operation
rstan copied to clipboard

read_stan_csv fails due to problems with regular expressions

Open jgabry opened this issue 4 years ago • 0 comments

Summary:

read_csv_header, which is called internally by read_stan_csv, will fail if the model name contains the string "thin" anywhere. In an example on the forums reported by @sdaza the Stan program was called "rethinking.stan". The problem is that this use of grep

https://github.com/stan-dev/rstan/blob/da2fc9c079534a82d3d26adda51ad17bf22f5e2b/rstan/rstan/R/misc.R#L1527-L1529

doesn't account for the possibility that "thin" shows up in other parts of the header besides the thin argument. Unfortunately it can show up in several other places if the model name contains "thin", e.g. in file, profile_file, and stancflags:

# output
#   file = /tmp/RtmphsRohn/rethinking-202110280252-1-434739.csv
#   diagnostic_file =  (Default)
#   refresh = 100 (Default)
#   sig_figs = -1 (Default)
#   profile_file = /tmp/RtmphsRohn/rethinking-profile-202110280252-1-54c303.csv
# num_threads = 10
# stanc_version = stanc3 v2.27.0
# stancflags = --name=rethinking_model

This eventually results in an error when read_stan_csv tries to use the value of thin.

Reproducible Steps:

Run the code provided in the discourse post by @sdaza:

https://discourse.mc-stan.org/t/problem-using-rstan-read-stan-csv/25017/5

Current Output:

Error

Expected Output:

No error

RStan Version:

2.21.2

R Version:

4.1.1

Operating System:

Mac big sur

jgabry avatar Nov 09 '21 19:11 jgabry