stan-dev / stan-dev/rstan

read_stan_csv fails due to problems with regular expressions

Open
#978 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
R
Stars
1.1k
Forks
266
Avg merge
2h 56m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in rstan/R/misc.R at the linked grep usage around lines 1527-1529, and trace how read_csv_header supplies the thin value to read_stan_csv. Reproduce the discourse example with a model name containing "thin"; done means read_stan_csv completes without treating occurrences in other header fields as the thin argument.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.