Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using sample_file fails as is_dir_writable checks for execute permissions #1125

Open
helske opened this issue Apr 23, 2024 · 0 comments
Open

Comments

@helske
Copy link

helske commented Apr 23, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant