Error in building CmdStanr on Windows 10

Can you post the entire error when running:

processx::run(
“pacman”,
args = c("-Syu", “mingw-w64-x86_64-make”,"–noconfirm"),
wd = file.path(Sys.getenv(“RTOOLS40_HOME”), “usr”, “bin”),
error_on_status = TRUE
)

Hi Rok,

This is the all error what I have got

Error in processx::run(“pacman”, args = c("-Syu", “mingw-w64-x86_64-make”, :
System command ‘pacman’ failed, exit status: 1, stderr:
E> error: target not found: �noconfirm
Type .Last.error.trace to see where the error occured

Then I run .Last.error.trace

Stack trace:

  1. processx::run(“pacman”, args = c("-Syu", “mingw-w64-x86_64-make”, …
  2. throw(new_process_error(res, call = sys.call(), echo = echo, …

x System command ‘pacman’ failed, exit status: 1, stderr:
E> error: target not found: �noconfirm

Ok, that is very weird. Have not seen that one before. Can you search for Rtools bash, open it and run

pacman -Syu mingw-w64-x86_64-make

there?

It is ,

nanayaer@MSOR-1D2FXF2 MSYS ~
$ pacman -Syu mingw-w64-x86_64-make
:: Synchronizing package databases…
mingw32 is up to date
mingw64 is up to date
:: Starting core system upgrade…
there is nothing to do
:: Starting full system upgrade…
resolving dependencies…
looking for conflicting packages…

Packages (3) mingw-w64-x86_64-expat-2.2.9-9002
mingw-w64-x86_64-gettext-0.19.8.1-9002
mingw-w64-x86_64-make-4.2.1-2

Total Download Size: 7.45 MiB
Total Installed Size: 55.23 MiB

:: Proceed with installation? [Y/n] Y
:: Retrieving packages…
mingw-w64-x86_64… 133.5 KiB 228 KiB/s 00:01 [#####################] 100%
mingw-w64-x86_64-gettext-0.19.8.1-9002-any 6.6 MiB 2.83 MiB/s 00:02 [############################################################] 100%
mingw-w64-x86_64-make-4.2.1-2-any 690.7 KiB 2.87 MiB/s 00:00 [############################################################] 100%
(3/3) checking keys in keyring [############################################################] 100%
(3/3) checking package integrity [############################################################] 100%
(3/3) loading package files [############################################################] 100%
(3/3) checking for file conflicts [############################################################] 100%
(3/3) checking available disk space [############################################################] 100%
:: Processing package changes…
(1/3) installing mingw-w64-x86_64-expat [############################################################] 100%
(2/3) installing mingw-w64-x86_64-gettext [############################################################] 100%
(3/3) installing mingw-w64-x86_64-make [############################################################] 100%

nanayaer@MSOR-1D2FXF2 MSYS ~
$

Cool. Now restart R and try install_cmdstan(). It should now work.

I think the error with pacman you saw is actually again forum formatting related “–noconfirm” (the dash is non-standard", should be -noconfirm).

I restarted R and installed cmdstanr using
install.packages(“cmdstanr”, repos = c(“https://mc-stan.org/r-packages/”, getOption(“repos”)))

and then run
library(cmdstanr)

It gave me,
This is cmdstanr version 0.1.3
- Online documentation and vignettes at mc-stan.org/cmdstanr
- CmdStan path set to: C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1
- Use set_cmdstan_path() to change the path
Warning messages:
1: Can’t find CmdStan makefile to detect version number. Path may not point to valid installation.
2: Can’t find CmdStan makefile to detect version number. Path may not point to valid installation.

And if you now run install_cmdstan?

It has already installed.

install_cmdstan()
Latest CmdStan release is v2.24.1
Installing CmdStan v2.24.1 in C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1
Downloading cmdstan-2.24.1.tar.gz from GitHub…
Warning message:
An installation already exists at C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1. Please remove or rename the installation folder or set overwrite=TRUE.

How about

install_cmdstan(cores = 2, overwrite = TRUE)

I am confused, why it is not working for me?

install_cmdstan(cores = 2, overwrite = TRUE)
Latest CmdStan release is v2.24.1
Installing CmdStan v2.24.1 in C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1
Downloading cmdstan-2.24.1.tar.gz from GitHub…
Removing the existing installation of CmdStan…
Download complete
Unpacking archive…
Error in mydir.create(name) :
failed to create directory ‘cmdstan-2.24.1/stan/lib/stan_math/lib/boost_1.72.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.24.1\stan\lib\stan_math\lib\boost_1.72.0\tools\auto_index\doc\html\boost_autoindex\tut\con’, reason ‘Invalid argument’

I am baffled as well. The toolchain seems to be installed properly.

Can you try:

install_cmdstan(dir = “xy”)

and set some path closer to C: instead of “xy”?

I tried with it as

install_cmdstan(dir = “C:/Users/nanayaer/Documents”)
Error in install_cmdstan(dir = “C:/Users/nanayaer/Documents”) :
could not find function “install_cmdstan”

But, I checked my .cmdstanr folder, it has cmdstan-2.24.1 folder and cmdstan-2.24.1.tar GZ file.

Does that mean cmdstan has already been installed ?

What if you try

set_cmdstan_path(“C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1”) and
then try to compile a model?

Yes, I set to path as what you suggested.
But, why is this warning message occurs ?

Warning message:
Can’t find CmdStan makefile to detect version number. Path may not point to valid installation.

I guess cmdstan has not been installed successfully.

Does this occur even if you run set_cmdstan_path(“C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1”)?

Can you check what is in the cmdstan-2.24.1 folder?

Yes, it’s the same warning.

cmdstan-2.24.1 folder has cmdstan-2.24.1 folder and cmdstan-2.24.1.tar GZ file.

Is the folder empty otherwise?

Hi Rok,

I deleted cmdstan folder and reinstalled all.
Then, I could run

set_cmdstan_path(“C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1/cmdstan-2.24.1”)
CmdStan path set to: C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1/cmdstan-2.24.1
cmdstan_path()
[1] “C:/Users/nanayaer/Documents/.cmdstanr/cmdstan-2.24.1/cmdstan-2.24.1”
cmdstan_version()
[1] “2.24.1”

When I tried to compile following, get an error

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

Compiling Stan program…
Error in rethrow_call(c_processx_exec, command, c(command, args), stdin, :
Command ‘mingw32-make.exe’ not found @win/processx.c:994 (processx_exec)
Type .Last.error.trace to see where the error occured

Great.

Now just run

processx::run(
“pacman”,
args = c("-Syu", “mingw-w64-x86_64-make”,"-noconfirm"),
wd = file.path(Sys.getenv(“RTOOLS40_HOME”), “usr”, “bin”),
error_on_status = TRUE
)

and

write('PATH="${RTOOLS40_HOME}\\usr\\bin;${RTOOLS40_HOME}\\mingw64\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)

and restart the R session.

It is done as follows and no errors.

install_mingw32_make <- function() {
processx::run(
“pacman”,
args = c("-Syu", “mingw-w64-x86_64-make”,"–noconfirm"),
wd = file.path(Sys.getenv(“RTOOLS40_HOME”), “usr”, “bin”),
error_on_status = TRUE
)
invisible(NULL)
}

write('PATH="${RTOOLS40_HOME}\\usr\\bin;${RTOOLS40_HOME}\\mingw64\\bin;${PATH}"', file = "~/.Renviron", append = TRUE)

Then, what will?

Thanks a lot