Error in building CmdStanr on Windows 10

Restart the R session and try installing again.

@rok_cesnovar @jonah
Hello Rok,

It is not clear for me what and why should I install again?

This is the place where I installed cmdstan in,
set_cmdstan_path(“C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1/cmdstan-2.24.1”)
Then I could run the commands
library(cmdstanr)
cmdstan_path()
[1] “C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1/cmdstan-2.24.1”
cmdstan_version()
[1] “2.24.1”

As I am following the link https://mc-stan.org/cmdstanr/articles/cmdstanr.html, I tried to compiling a model

file <- file.path(cmdstan_path(), “examples”, “bernoulli”, “bernoulli.stan”)
mod <- cmdstan_model(file)

This is what I got then,

Compiling Stan program…
INFO: Could not find files for the given pattern(s).
Error: An error occured during compilation! See the message above for more information

Am I in the write track or what do you recommend to do?

Many thanks for you.

I’m running into the same issue when attempting to install cmdstan version 2.27 on my Windows machine. Just like in the OPs original error message I’m getting the error when it’s attempting to create the con folder in the boost_1.72.0 directory. In my older install of cmdstan version 2.26.1 there is no con directory and instead there is a configure folder. It seems that con is reserved by Windows. Any ideas?

1 Like

I worked around this by downloading the latest release of cmdstan from github. I put the extracted cmdstan-2.27.0 folder where my previous cmdstan version was and the cmdstanr package picked up the latest version after restarting my R session. After that it worked with no problems. I’m not sure what’s going on with the con/configure folder issue I mentioned above but with the downloaded latest release from github the folder is named configure in the boost_1.75.0 directory.

1 Like

Glad you got it working and sorry for the hassle. @rok_cesnovar Any idea what’s going on with this issue on Windows? Can we do something in cmdstanr::install_cmdstan() to avoid this problem?

2 Likes

To me, this looks like the download or unpackaging of the tarball has failed. Its a bit weird its the same folder in both error reports, but given that manual installation has fixed this, its also not a C++ toolchain issue.

Maybe we could check the downloaded tarball somehow? Or if it unpackaged correctly?

Hello all. I’m just starting with cmdstanr and I had the same problem, just wanted to know if this issue has been solved in a release or if the fix is still to download the version directly?

Thanks a lot.

Hi,

I also ended up with the same issue today.

> cmdstanr::install_cmdstan()
The C++ toolchain required for CmdStan is setup properly!
trying URL 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'
Content type 'application/json; charset=utf-8' length 14641 bytes (14 KB)
downloaded 14 KB

* Latest CmdStan release is v2.32.2
* Installing CmdStan v2.32.2 in C:/Users/frenys/Documents/.cmdstan/cmdstan-2.32.2
* Downloading cmdstan-2.32.2.tar.gz from GitHub...
trying URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.32.2/cmdstan-2.32.2.tar.gz'
Content type 'application/octet-stream' length 50452148 bytes (48.1 MB)
downloaded 48.1 MB

* Download complete
* Unpacking archive...
Error in mydir.create(name) : 
  failed to create directory ‘cmdstan-2.32.2/stan/lib/stan_math/lib/boost_1.78.0/tools/auto_index/doc/html/boost_autoindex/tut/con’
In addition: Warning message:
In dir.create(path, showWarnings = TRUE, recursive = TRUE, ...) :
  cannot create dir 'cmdstan-2.32.2\stan\lib\stan_math\lib\boost_1.78.0\tools\auto_index\doc\html\boost_autoindex\tut\con', reason 'Invalid argument'

The solution from @joshualeond worked, I downloaded the .tar.gz and extracted it using 7-zip and moved it into place.

I would like to add more information to the error itself though.

The ´con´ directory that is failing is actually ´configure´, and interestingly the directory string is truncated at 100 bytes.

> stringr::str_length("cmdstan-2.32.2/stan/lib/stan_math/lib/boost_1.78.0/tools/auto_index/doc/html/boost_autoindex/tut/con")
[1] 100

And a short google away indicates that filepaths more than 100 bytes long should be avoided.https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/tar

I did not investigate further. It seems you can allow it by adding certain flags to the tar process command in install.R in cmdstanr repository. The utils::tar documentation recommends file paths shorter than 100 bytes for maximum portability. I would assume the most portable (and tedious) solution would to reorganize the file structure of cmdstan to accomodate that.

2 Likes

I had the same issue and worked around by downloading release of Stan, but to get things working I also needed complete the installation by running the install_tbb.bat script and then

cmdstanr:::build_cmdstan("~/.cmdstan/cmdstan-2.34.1/", cores = 10, quiet = FALSE, timeout = 1200)

(obviously replace the number of cores and directory with values that work for you)

1 Like

I think, I am having the same or a similar issue today (Windows 10; R version: 4.3.3.; cmdstanr version: 0.71; cmdstan version: 2.34.1).

When running

cmdstanr::install_cmdstan()

I reveived the same error as described above:

*Unpacking archive...
Error in mydir.create(name) : 
  failed to create directory ‘cmdstan-2.34.1/stan/lib/stan_math/lib/boost_1.81.0/tools/auto_index/doc/html/boost_autoindex/tut/con’
In addition: Warning message:
In dir.create(path, showWarnings = TRUE, recursive = TRUE, ...) :
  cannot create dir 'cmdstan-2.34.1\stan\lib\stan_math\lib\boost_1.81.0\tools\auto_index\doc\html\boost_autoindex\tut\con', reason 'Invalid argument'

I followed @joshualeond s suggestion, downloaded “cmdstan-2.34.1” from github, and replaced the previous cmdstan version with the extracted files from github (including the extracted folder “cmdstan-2.34.1” and the file “cmdstan-2.34.1.tar”).

This appears to work fine, I can run

library(cmdstanr)

which gives me:

This is cmdstanr version 0.7.1 
- CmdStanR documentation and vignettes: mc-stan.org/cmdstanr
- CmdStan path: C:/Users/botzet/Documents/.cmdstan/cmdstan-2.34.1
- CmdStan version: 2.34.1

When I run

check_cmdstan_toolchain()
cmdstan_path()
cmdstan_version()

it says

The C++ toolchain required for CmdStan is setup properly!

"C:/Users/botzet/Documents/.cmdstan/cmdstan-2.34.1"

"2.34.1"

But if I try the example models (or any other models)

file <- file.path(cmdstan_path(), "examples", "bernoulli", "bernoulli.stan")
mod <- cmdstan_model(file)

I receive the following error message:

Compiling Stan program...
Error in `(function (command = NULL, args = character(), error_on_status = TRUE, …`:
! System command 'make' failed
---
Exit status: 2
Stderr:
INFORMATION: Es konnten keine Dateien mit dem angegebenen
Muster gefunden werden.
makefile:144: stan/lib/stan_math/make/compiler_flags: No such file or directory
make: *** [makefile:359: stan/lib/stan_math/make/compiler_flags] Error 1
---
Type .Last.error to see the more details.

I have also tried @martinmodrak s solution, ran the install_tbb.bat script and then used the following code:

cmdstanr:::build_cmdstan("~/.cmdstan/cmdstan-2.34.1/", cores = 10, quiet = FALSE, timeout = 1200)

which then gives me the following error:

ERROR: Missing Stan submodules.
We tried to find the Stan Math submodule at:
stan/lib/stan_math/

The most likely source of the problem is CmdStan was cloned without the --recursive flag. To fix this, run the following command:
git submodule update --init --recursive
And try building again

My folder “.cmdstan\cmdstan-2.34.1\stan” is completely empty - maybe that is the problem? Maybe Ive downloaded the wrong folder from github (Ive used the folder Source code (zip) from Release v2.34.1 (23 January 2024) · stan-dev/cmdstan · GitHub)?

I would really appreciate any help.

1 Like

Alright, I was able to solve this issue relatively quickly by installing cmdstanr and running
cmdstanr::install_cmdstan() directly in R instead of RStudio (…rookie mistake). Now it works without any problems

2 Likes

I have the same problem on Windows 10

failed to create directory 'cmdstan-2.34.1/stan/lib/stan_math/lib/boost_1.81.0/tools/auto_index/doc/html/boost_autoindex/tut/con'

after a fresh installation of R 4.2.3) with Rtools 4.2. First, I typed in the Windows command line

cmdstanr::install_cmdstan()

but I was asked to first run

cmdstanr::check_cmdstan_toolchain(fix = TRUE)

then again

cmdstanr::install_cmdstan()

throws the error

The C++ toolchain required for CmdStan is setup properly!
trying URL 'https://api.github.com/repos/stan-dev/cmdstan/releases/latest'
Content type 'application/json; charset=utf-8' length 17560 bytes (17 KB)
downloaded 17 KB

* Latest CmdStan release is v2.34.1
* Installing CmdStan v2.34.1 in C:\Users\xxx\Documents/.cmdstan/cmdstan-2.34.1
* Downloading cmdstan-2.34.1.tar.gz from GitHub...
trying URL 'https://github.com/stan-dev/cmdstan/releases/download/v2.34.1/cmdstan-2.34.1.tar.gz'
Content type 'application/octet-stream' length 51577679 bytes (49.2 MB)
downloaded 49.2 MB

* Download complete
* Unpacking archive...
Error in mydir.create(name) :
  failed to create directory 'cmdstan-2.34.1/stan/lib/stan_math/lib/boost_1.81.0/tools/auto_index/doc/html/boost_autoindex/tut/con'
In addition: Warning message:
In dir.create(path, showWarnings = TRUE, recursive = TRUE, ...) :
  cannot create dir 'cmdstan-2.34.1\stan\lib\stan_math\lib\boost_1.81.0\tools\auto_index\doc\html\boost_autoindex\tut\con', reason 'Invalid argument'

The error seems to be related to the doc.

I normally use cmdstanr on Linux just fine, but I am preparing a workshop so I was trying to set up the environment on Windows too (btw, rstan works).

Woudl you be able to help?

Ok, I should have read the previous posts more attentively. For posterity:

  • Install R, Rtools, cmdstanr, etc
  • Follow the instruction here to set up the toolchain CmdStan Installation # RTools42 & RTools43. In summary, after Rtools is installed, update the Path environment variable by adding C:\rtools42\usr\bin and C:\rtools42\ucrt64\bin. Then, you need to install the mingw32-make utility and some additional compiler dependencies. Navigate to the installation directory of the Rtools toolchain and launch msys2.exe file and type pacman -Sy mingw-w64-ucrt-x86_64-make mingw-w64-ucrt-x86_64-gcc.
  • Type in the R console cmdstanr::check_cmdstan_toolchain(fix = TRUE)
  • Download the files for cmdstan here and unzip the content so that you have all the files inside <your user>/Documents/.cmdstan/cmdstan-2.34.1.
  • In the console run cmdstanr::set_cmdstan_path(). If this does not work, then type cmdstanr::set_cmdstan_path("<your user>/Documents/.cmdstan/cmdstan-2.34.1").

To test that everything has been set up correctly, start a R session and type cmdstanr::cmdstanr_example('logistic'). It should compile and sample a model.

Could the information on how to install cmdstan from the github release files be written in CmdStan Installation (mc-stan.org)? It is much easier than compiling the whole thing from source. Or at least, could you add an entry at CmdStan Installation # Common-problems for this specific error that affects many Windows users.

We’re always happy to make the documentation clearer, but I’m not sure what you’re requesting. What you just described is “compiling the whole thing from source”

Yeah sorry, that was some sloppy text.

What I meant is that the instructions (CmdStan Installation (mc-stan.org)) suggest to either use Conda or to compile the source from Github. I thought, we could add the option to use precompiled binaries instead, the ones at Releases · stan-dev/cmdstan (github.com).

Does it make sense?