stan-dev / stan-dev/rstan

Too Many Items error when reading large CSV

Open
#530 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Summary:

When reading in posterior samples from a CSV with more than INT_MAX total elements (2,147,483,647), the CSV cannot be loaded.

Description:

Due to Rstan's reliance on the base R's scan function to load the CSV. It is limited by the R vector size.

This was also documented here:
https://groups.google.com/forum/#!topic/stan-users/XvroDYe_yJc

Even though R supports long vectors, they are not yet implemented in the scan function. I created a patch to the scan function here, which fixes the issue.

https://gist.github.com/aaronjg/f39e5966687ca004dab5a10e7655c648

There may also be a way to fix this without patching base R using read.table rather than scan, since that doesn't require loading everything into a single vector.

Reproducible Steps:

Generate a stan output CSV with more than INT_MAX total values, and try to load into stan using the read_stan_csv function.

Current Output:

Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings, :
too many items
Calls: stan -> sampling -> sampling -> .local -> scan

Expected Output:

RStan should read this correctly

RStan Version:

2.17.2

R Version:

3.5.0

Operating System:

Ubuntu, 64 bit.

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 at read_stan_csv and trace the sampling -> .local -> scan call shown in the error. Compare the existing scan-based loading with the suggested read.table approach or the linked base R scan patch, then reproduce with a CSV exceeding INT_MAX total elements. Done means RStan can load that CSV without the “too many items” error.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.