Error in cmdstanr after installing cmdstanr

I have an error when I try to use “cmdstanr”. Although I could have installed and check the version of cmdstanr.

The code is below.

install.packages("cmdstanr", repos = c("https://mc-stan.org/r-packages/", getOption("repos")))
library(rstan)
library(cmdstanr)
check_cmdstan_toolchain(fix = TRUE)
install_cmdstan(cores = 2)
cmdstan_version()   # I can check the version of cmdstan

model <- cmdstan_model(write_stan_file("parameters{real m;}model{5~normal(m,1);} "))      # error occurs
model$sample()

The results is below.

> install_cmdstan(cores = 2)
The C++ toolchain required for CmdStan is setup properly!
* Latest CmdStan release is v2.32.1
* Installing CmdStan v2.32.1 in C:\Users\d21601\Documents/.cmdstan/cmdstan-2.32.1
* Downloading cmdstan-2.32.1.tar.gz from GitHub...
 警告メッセージ: 
1:  readChar(make_local_path, file.info(make_local_path)$size) で: 
   UTF-8 以外のマルチバイトロケールではバイト型でのみ読み込み可能です 
2: An installation already exists at C:\Users\d21601\Documents/.cmdstan/cmdstan-2.32.1. Please remove or rename the installation folder or set overwrite=TRUE. 

> cmdstan_version()   # check version
[1] "2.32.1"

> model <- cmdstan_model(write_stan_file("parameters{real m;}model{5~normal(m,1);} "))
Compiling Stan program...
情報: 与えられたパターンのファイルが見つかりませんでした。

In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array/multi_array_ref.hpp:32,

~(omit some sentences.)~

mingw32-make: *** [make/program:14: src/cmdstan/main.o] Error 1

 エラー: An error occured during compilation! See the message above for more information.

  • Operating System: mingw32
  • language: R version 4.2.1
  • Rtools: rtools42
  • CmdStan Version: “2.32.1”
  • Compiler/Toolkit:

If a lack of information exist, please tell me. Thanks in advance.

I don’t know exactly the error, but the string “5~” in the model code looks strange to me

Thank you for replying.
I followed the example of this URL.
I just want to check if ‘cmdstanr’ works well or not.

Are you able to share the full output without anything cut out?

I’m sorry I’m late.
All error messages are below.

Compiling Stan program...
情報: 与えられたパターンのファイルが見つかりませんでした。

In file included from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array/multi_array_ref.hpp:32,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/multi_array.hpp:34,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint/algebra/multi_array_algebra.hpp:22,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/numeric/odeint.hpp:63,
                 from stan/lib/stan_math/stan/math/prim/functor/ode_rk45.hpp:9,
                 from stan/lib/stan_math/stan/math/prim/functor/integrate_ode_rk45.hpp:6,
                 from stan/lib/stan_math/stan/math/prim/functor.hpp:15,
                 from stan/lib/stan_math/stan/math/prim.hpp:15,
                 from stan/src/stan/io/dump.hpp:7,
                 from src/cmdstan/command_helper.hpp:5,
                 from src/cmdstan/command.hpp:14,
                 from src/cmdstan/main.cpp:1:
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:180:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  180 |         : public boost::functional::detail::unary_function<typename unary_traits<Predicate>::argument_type,bool>
      |                                             ^~~~~~~~~~~~~~

In file included from C:/rtools42/ucrt64/include/c++/13.1.0/string:49,
                 from C:/rtools42/ucrt64/include/c++/13.1.0/bits/locale_classes.h:40,
                 from C:/rtools42/ucrt64/include/c++/13.1.0/bits/ios_base.h:41,
                 from C:/rtools42/ucrt64/include/c++/13.1.0/streambuf:43,
                 from C:/rtools42/ucrt64/include/c++/13.1.0/bits/streambuf_iterator.h:35,
                 from C:/rtools42/ucrt64/include/c++/13.1.0/iterator:66,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/iterator/iterator_traits.hpp:10,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/range/iterator_range_core.hpp:26,
                 from stan/lib/stan_math/lib/boost_1.78.0/boost/lexical_cast.hpp:30,
                 from stan/src/stan/callbacks/writer.hpp:4,
                 from src/cmdstan/arguments/argument.hpp:4,
                 from src/cmdstan/arguments/categorical_argument.hpp:4,
                 from src/cmdstan/arguments/arg_data.hpp:4,
                 from src/cmdstan/command.hpp:4:
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:214:45: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  214 |         : public boost::functional::detail::binary_function<
      |                                             ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:252:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  252 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:299:45: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  299 |         : public boost::functional::detail::unary_function<
      |                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:345:57: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  345 |     class mem_fun_t : public boost::functional::detail::unary_function<T*, S>
      |                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:361:58: warnin
g: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  361 |     class mem_fun1_t : public boost::functional::detail::binary_function<T*, A, S>
      |                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:377:63: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  377 |     class const_mem_fun_t : public boost::functional::detail::unary_function<const T*, S>
      |                                                               ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~

stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:393:64: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  393 |     class const_mem_fun1_t : public boost::functional::detail::binary_function<const T*, A, S>
      |                                                                ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:438:61: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  438 |     class mem_fun_ref_t : public boost::functional::detail::unary_function<T&, S>
      |                                                             ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:454:62: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  454 |     class mem_fun1_ref_t : public boost::functional::detail::binary_function<T&, A, S>
      |                                                              ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:470:67: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  470 |     class const_mem_fun_ref_t : public boost::functional::detail::unary_function<const T&, S>
      |                                                                   ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl
_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:487:68: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  487 |     class const_mem_fun1_ref_t : public boost::functional::detail::binary_function<const T&, A, S>
      |                                                                    ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:533:73: warning: 'template<class _Arg, class _Result> struct std::unary_function' is deprecated [-Wdeprecated-declarations]
  533 |     class pointer_to_unary_function : public boost::functional::detail::unary_function<Arg,Result>
      |                                                                         ^~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:117:12: note: declared here
  117 |     struct unary_function
      |            ^~~~~~~~~~~~~~
stan/lib/stan_math/lib/boost_1.78.0/boost/functional.hpp:557:74: warning: 'template<class _Arg1, class _Arg2, class _Result> struct std::binary_function' is deprecated [-Wdeprecated-declarations]
  557 |     class pointer_to_binary_function : public boost::functional::detail::binary_function<Arg1,Arg2,Result>
      |                                                                          ^~~~~~~~~~~~~~~
C:/rtools42/ucrt64/include/c++/13.1.0/bits/stl_function.h:131:12: note: declared here
  131 |     struct binary_function
      |            ^~~~~~~~~~~~~~~

In file included from stan/lib/stan_math/stan/math/rev/fun.hpp:74,
                 from stan/lib/stan_math/stan/math/rev.hpp:10,
                 from stan/src/stan/model/log_prob_grad.hpp:4,
                 from src/cmdstan/command_helper.hpp:10:
stan/lib/stan_math/stan/math/rev/fun/generalized_inverse.hpp: In function 'auto stan::math::generalized_inverse(const VarMat&)':
stan/lib/stan_math/stan/math/rev/fun/generalized_inverse.hpp:67: note: '-Wmisleading-indentation' is disabled from this point onwards, since column-tracking was disabled due to the size of the code/headers
   67 |   if (G.size() == 0)
      | 

stan/lib/stan_math/stan/math/rev/fun/generalized_inverse.hpp:67: note: adding '-flarge-source-files' will allow for more column-tracking support, at the expense of compilation time and memory

mingw32-make: *** [make/program:14: src/cmdstan/main.o] Error 1

 エラー: An error occured during compilation! See the message above for more information.

I would recommend to reinstall cmdstan and check if the bernoulli code can be compiled without errors (it looks like it was not installed properly)

Hiroki, I have the same problem as yours. Have you figured out a solution?

I referred the following page.
I guess that this problem occurs when you can’t set the PATH of the Rtools4.2.