stan-dev / stan-dev/rstan

Using `sample_file` fails as `is_dir_writable` checks for execute permissions

Open
#1,125 0 comments 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:

You can't save the CSV output of Stan user-defined files if the user does not have execute permissions on that folder.

Description:

When using sample_file and diagnostic_file arguments, the file path permissions are checked with the is_dir_writable function:

rstan:::is_dir_writable
function (path) 
{
    (file.access(path, mode = 2) == 0) && (file.access(path, 
        mode = 1) == 0)
}

Because the second condition checks for execute permissions, the path is not used if these permissions do not exist. However, at least for saving the CSV files, such permissions are not needed.

Reproducible Steps:

When using

m <- stan_model(model_code = 'parameters {real y;} model {y ~ normal(0,1);}')
f <- sampling(m, iter = 100, sample_file = "W:/debug/samples.csv", cores= 1) # with multiple cores the warning is not shown

I get a warning "W:/debug" is not writable; use "W:\debug\tmp\Rtmp6tv72d" instead. But changing to that folder gives the same error due to the lack of execute permissions on our server.

But mocking the is_dir_writable function so that it always returns TRUE, allows me to performs sampling to samples.csv without any problems:

mockthat::local_mock(is_dir_writable = TRUE, mock_env = "rstan")
f <- sampling(m, iter = 100, sample_file = "W:/debug/samples.csv", cores= 1)
fit <- read_stan_csv(c("W:/debug/samples_1.csv", "W:/debug/samples_2.csv"))
RStan Version:

2.32.6

R Version:

4.3.1

Operating System:

Windows 10

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 rstan:::is_dir_writable and trace how sampling handles the sample_file and diagnostic_file paths, reproducing the warning with the provided sample_file example and cores=1. Done means CSV output can be saved to a writable directory without requiring execute permission, while genuinely unwritable paths still receive the appropriate fallback behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.