Dealing with R 4.0.2 - RStan

Hello,

I am trying to run a simplre brms formula,r

>  m2 <- brm(f1 + f2 + set_rescor(FALSE), data = jobs, cores = 4)

and I get the following error:

Compiling the C++ model
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file4c43b0a3906.cpp 2> file4c43b0a3906.cpp.err.txt' had status 1
2: In file(con, "r") :
  cannot open file 'file4c43b0a3906.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

Operating System: Windows 10
Interface Version: R 4.0.2
Compiler/Toolkit: library(brms)

Thanks in advance for any comment on this regard.

Best,

Julian

Can you do

example(stan_model, package = "rstan", run.dontrun = TRUE)

and tell us the part under “Compilation argument:”?

example(stan_model, package = “rstan”, run.dontrun = TRUE)
Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.19.3, GitRev: 2e1f913d3ca3)
For execution on a local, multicore CPU with excess RAM we recommend calling
options(mc.cores = parallel::detectCores()).
To avoid recompilation of unchanged Stan programs, we recommend calling
rstan_options(auto_write = TRUE)
For improved execution time, we recommend calling
Sys.setenv(LOCAL_CPPFLAGS = ‘-march=corei7 -mtune=corei7’)
although this causes Stan to throw an error on a few processors.

stn_md> stancode <- 'data {real y_mean;} parameters {real y;} model {y ~ normal(y_mean,1);}'

stn_md> mod <- stan_model(model_code = stancode, verbose = TRUE)

TRANSLATING MODEL '73fc79f8b1915e8208c736914c86d1a1' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '73fc79f8b1915e8208c736914c86d1a1'.
COMPILING THE C++ CODE FOR MODEL '73fc79f8b1915e8208c736914c86d1a1' NOW.
OS: x86_64, mingw32; rstan: 2.19.3; Rcpp: 1.0.4.6; inline: 0.3.15 
 >> setting environment variables: 
PKG_LIBS =  -L"C:/Users/gavirial/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders
PKG_CPPFLAGS =   -I"C:/Users/gavirial/Documents/R/win-library/4.0/Rcpp/include/"  -I"C:/Users/gavirial/Documents/R/win-library/4.0/RcppEigen/include/"  -I"C:/Users/gavirial/Documents/R/win-library/4.0/RcppEigen/include/unsupported"  -I"C:/Users/gavirial/Documents/R/win-library/4.0/BH/include" -I"C:/Users/gavirial/Documents/R/win-library/4.0/StanHeaders/include/src/"  -I"C:/Users/gavirial/Documents/R/win-library/4.0/StanHeaders/include/"  -I"C:/Users/gavirial/Documents/R/win-library/4.0/rstan/include" -DEIGEN_NO_DEBUG  -D_REENTRANT  -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -include stan/math/prim/mat/fun/Eigen.hpp  -std=c++1y
 >> Program source :

   1 : 
   2 : // includes from the plugin
   3 : // [[Rcpp::plugins(cpp14)]]
   4 : 
   5 : // user includes
   6 : #define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
   7 : #include <rstan/rstaninc.hpp>
   8 : // Code generated by Stan version 2.21.0
   9 : 
  10 : #include <stan/model/model_header.hpp>
  11 : 
  12 : namespace model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace {
  13 : 
  14 : using std::istream;
  15 : using std::string;
  16 : using std::stringstream;
  17 : using std::vector;
  18 : using stan::io::dump;
  19 : using stan::math::lgamma;
  20 : using stan::model::prob_grad;
  21 : using namespace stan::math;
  22 : 
  23 : static int current_statement_begin__;
  24 : 
  25 : stan::io::program_reader prog_reader__() {
  26 :     stan::io::program_reader reader;
  27 :     reader.add_event(0, 0, "start", "model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1");
  28 :     reader.add_event(3, 1, "end", "model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1");
  29 :     return reader;
  30 : }
  31 : 
  32 : class model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1
  33 :   : public stan::model::model_base_crtp<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1> {
  34 : private:
  35 :         double y_mean;
  36 : public:
  37 :     model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__,
  38 :         std::ostream* pstream__ = 0)
  39 :         : model_base_crtp(0) {
  40 :         ctor_body(context__, 0, pstream__);
  41 :     }
  42 : 
  43 :     model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1(stan::io::var_context& context__,
  44 :         unsigned int random_seed__,
  45 :         std::ostream* pstream__ = 0)
  46 :         : model_base_crtp(0) {
  47 :         ctor_body(context__, random_seed__, pstream__);
  48 :     }
  49 : 
  50 :     void ctor_body(stan::io::var_context& context__,
  51 :                    unsigned int random_seed__,
  52 :                    std::ostream* pstream__) {
  53 :         typedef double local_scalar_t__;
  54 : 
  55 :         boost::ecuyer1988 base_rng__ =
  56 :           stan::services::util::create_rng(random_seed__, 0);
  57 :         (void) base_rng__;  // suppress unused var warning
  58 : 
  59 :         current_statement_begin__ = -1;
  60 : 
  61 :         static const char* function__ = "model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1";
  62 :         (void) function__;  // dummy to suppress unused var warning
  63 :         size_t pos__;
  64 :         (void) pos__;  // dummy to suppress unused var warning
  65 :         std::vector<int> vals_i__;
  66 :         std::vector<double> vals_r__;
  67 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
  68 :         (void) DUMMY_VAR__;  // suppress unused var warning
  69 : 
  70 :         try {
  71 :             // initialize data block variables from context__
  72 :             current_statement_begin__ = 1;
  73 :             context__.validate_dims("data initialization", "y_mean", "double", context__.to_vec());
  74 :             y_mean = double(0);
  75 :             vals_r__ = context__.vals_r("y_mean");
  76 :             pos__ = 0;
  77 :             y_mean = vals_r__[pos__++];
  78 : 
  79 : 
  80 :             // initialize transformed data variables
  81 :             // execute transformed data statements
  82 : 
  83 :             // validate transformed data
  84 : 
  85 :             // validate, set parameter ranges
  86 :             num_params_r__ = 0U;
  87 :             param_ranges_i__.clear();
  88 :             current_statement_begin__ = 1;
  89 :             num_params_r__ += 1;
  90 :         } catch (const std::exception& e) {
  91 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
  92 :             // Next line prevents compiler griping about no return
  93 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
  94 :         }
  95 :     }
  96 : 
  97 :     ~model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1() { }
  98 : 
  99 : 
 100 :     void transform_inits(const stan::io::var_context& context__,
 101 :                          std::vector<int>& params_i__,
 102 :                          std::vector<double>& params_r__,
 103 :                          std::ostream* pstream__) const {
 104 :         typedef double local_scalar_t__;
 105 :         stan::io::writer<double> writer__(params_r__, params_i__);
 106 :         size_t pos__;
 107 :         (void) pos__; // dummy call to supress warning
 108 :         std::vector<double> vals_r__;
 109 :         std::vector<int> vals_i__;
 110 : 
 111 :         current_statement_begin__ = 1;
 112 :         if (!(context__.contains_r("y")))
 113 :             stan::lang::rethrow_located(std::runtime_error(std::string("Variable y missing")), current_statement_begin__, prog_reader__());
 114 :         vals_r__ = context__.vals_r("y");
 115 :         pos__ = 0U;
 116 :         context__.validate_dims("parameter initialization", "y", "double", context__.to_vec());
 117 :         double y(0);
 118 :         y = vals_r__[pos__++];
 119 :         try {
 120 :             writer__.scalar_unconstrain(y);
 121 :         } catch (const std::exception& e) {
 122 :             stan::lang::rethrow_located(std::runtime_error(std::string("Error transforming variable y: ") + e.what()), current_statement_begin__, prog_reader__());
 123 :         }
 124 : 
 125 :         params_r__ = writer__.data_r();
 126 :         params_i__ = writer__.data_i();
 127 :     }
 128 : 
 129 :     void transform_inits(const stan::io::var_context& context,
 130 :                          Eigen::Matrix<double, Eigen::Dynamic, 1>& params_r,
 131 :                          std::ostream* pstream__) const {
 132 :       std::vector<double> params_r_vec;
 133 :       std::vector<int> params_i_vec;
 134 :       transform_inits(context, params_i_vec, params_r_vec, pstream__);
 135 :       params_r.resize(params_r_vec.size());
 136 :       for (int i = 0; i < params_r.size(); ++i)
 137 :         params_r(i) = params_r_vec[i];
 138 :     }
 139 : 
 140 : 
 141 :     template <bool propto__, bool jacobian__, typename T__>
 142 :     T__ log_prob(std::vector<T__>& params_r__,
 143 :                  std::vector<int>& params_i__,
 144 :                  std::ostream* pstream__ = 0) const {
 145 : 
 146 :         typedef T__ local_scalar_t__;
 147 : 
 148 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 149 :         (void) DUMMY_VAR__;  // dummy to suppress unused var warning
 150 : 
 151 :         T__ lp__(0.0);
 152 :         stan::math::accumulator<T__> lp_accum__;
 153 :         try {
 154 :             stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 155 : 
 156 :             // model parameters
 157 :             current_statement_begin__ = 1;
 158 :             local_scalar_t__ y;
 159 :             (void) y;  // dummy to suppress unused var warning
 160 :             if (jacobian__)
 161 :                 y = in__.scalar_constrain(lp__);
 162 :             else
 163 :                 y = in__.scalar_constrain();
 164 : 
 165 :             // model body
 166 : 
 167 :             current_statement_begin__ = 1;
 168 :             lp_accum__.add(normal_log<propto__>(y, y_mean, 1));
 169 : 
 170 :         } catch (const std::exception& e) {
 171 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 172 :             // Next line prevents compiler griping about no return
 173 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 174 :         }
 175 : 
 176 :         lp_accum__.add(lp__);
 177 :         return lp_accum__.sum();
 178 : 
 179 :     } // log_prob()
 180 : 
 181 :     template <bool propto, bool jacobian, typename T_>
 182 :     T_ log_prob(Eigen::Matrix<T_,Eigen::Dynamic,1>& params_r,
 183 :                std::ostream* pstream = 0) const {
 184 :       std::vector<T_> vec_params_r;
 185 :       vec_params_r.reserve(params_r.size());
 186 :       for (int i = 0; i < params_r.size(); ++i)
 187 :         vec_params_r.push_back(params_r(i));
 188 :       std::vector<int> vec_params_i;
 189 :       return log_prob<propto,jacobian,T_>(vec_params_r, vec_params_i, pstream);
 190 :     }
 191 : 
 192 : 
 193 :     void get_param_names(std::vector<std::string>& names__) const {
 194 :         names__.resize(0);
 195 :         names__.push_back("y");
 196 :     }
 197 : 
 198 : 
 199 :     void get_dims(std::vector<std::vector<size_t> >& dimss__) const {
 200 :         dimss__.resize(0);
 201 :         std::vector<size_t> dims__;
 202 :         dims__.resize(0);
 203 :         dimss__.push_back(dims__);
 204 :     }
 205 : 
 206 :     template <typename RNG>
 207 :     void write_array(RNG& base_rng__,
 208 :                      std::vector<double>& params_r__,
 209 :                      std::vector<int>& params_i__,
 210 :                      std::vector<double>& vars__,
 211 :                      bool include_tparams__ = true,
 212 :                      bool include_gqs__ = true,
 213 :                      std::ostream* pstream__ = 0) const {
 214 :         typedef double local_scalar_t__;
 215 : 
 216 :         vars__.resize(0);
 217 :         stan::io::reader<local_scalar_t__> in__(params_r__, params_i__);
 218 :         static const char* function__ = "model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::write_array";
 219 :         (void) function__;  // dummy to suppress unused var warning
 220 : 
 221 :         // read-transform, write parameters
 222 :         double y = in__.scalar_constrain();
 223 :         vars__.push_back(y);
 224 : 
 225 :         double lp__ = 0.0;
 226 :         (void) lp__;  // dummy to suppress unused var warning
 227 :         stan::math::accumulator<double> lp_accum__;
 228 : 
 229 :         local_scalar_t__ DUMMY_VAR__(std::numeric_limits<double>::quiet_NaN());
 230 :         (void) DUMMY_VAR__;  // suppress unused var warning
 231 : 
 232 :         if (!include_tparams__ && !include_gqs__) return;
 233 : 
 234 :         try {
 235 :             if (!include_gqs__ && !include_tparams__) return;
 236 :             if (!include_gqs__) return;
 237 :         } catch (const std::exception& e) {
 238 :             stan::lang::rethrow_located(e, current_statement_begin__, prog_reader__());
 239 :             // Next line prevents compiler griping about no return
 240 :             throw std::runtime_error("*** IF YOU SEE THIS, PLEASE REPORT A BUG ***");
 241 :         }
 242 :     }
 243 : 
 244 :     template <typename RNG>
 245 :     void write_array(RNG& base_rng,
 246 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& params_r,
 247 :                      Eigen::Matrix<double,Eigen::Dynamic,1>& vars,
 248 :                      bool include_tparams = true,
 249 :                      bool include_gqs = true,
 250 :                      std::ostream* pstream = 0) const {
 251 :       std::vector<double> params_r_vec(params_r.size());
 252 :       for (int i = 0; i < params_r.size(); ++i)
 253 :         params_r_vec[i] = params_r(i);
 254 :       std::vector<double> vars_vec;
 255 :       std::vector<int> params_i_vec;
 256 :       write_array(base_rng, params_r_vec, params_i_vec, vars_vec, include_tparams, include_gqs, pstream);
 257 :       vars.resize(vars_vec.size());
 258 :       for (int i = 0; i < vars.size(); ++i)
 259 :         vars(i) = vars_vec[i];
 260 :     }
 261 : 
 262 :     std::string model_name() const {
 263 :         return "model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1";
 264 :     }
 265 : 
 266 : 
 267 :     void constrained_param_names(std::vector<std::string>& param_names__,
 268 :                                  bool include_tparams__ = true,
 269 :                                  bool include_gqs__ = true) const {
 270 :         std::stringstream param_name_stream__;
 271 :         param_name_stream__.str(std::string());
 272 :         param_name_stream__ << "y";
 273 :         param_names__.push_back(param_name_stream__.str());
 274 : 
 275 :         if (!include_gqs__ && !include_tparams__) return;
 276 : 
 277 :         if (include_tparams__) {
 278 :         }
 279 : 
 280 :         if (!include_gqs__) return;
 281 :     }
 282 : 
 283 : 
 284 :     void unconstrained_param_names(std::vector<std::string>& param_names__,
 285 :                                    bool include_tparams__ = true,
 286 :                                    bool include_gqs__ = true) const {
 287 :         std::stringstream param_name_stream__;
 288 :         param_name_stream__.str(std::string());
 289 :         param_name_stream__ << "y";
 290 :         param_names__.push_back(param_name_stream__.str());
 291 : 
 292 :         if (!include_gqs__ && !include_tparams__) return;
 293 : 
 294 :         if (include_tparams__) {
 295 :         }
 296 : 
 297 :         if (!include_gqs__) return;
 298 :     }
 299 : 
 300 : }; // model
 301 : 
 302 : }  // namespace
 303 : 
 304 : typedef model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1 stan_model;
 305 : 
 306 : #ifndef USING_R
 307 : 
 308 : stan::model::model_base& new_model(
 309 :         stan::io::var_context& data_context,
 310 :         unsigned int seed,
 311 :         std::ostream* msg_stream) {
 312 :   stan_model* m = new stan_model(data_context, seed, msg_stream);
 313 :   return *m;
 314 : }
 315 : 
 316 : #endif
 317 : 
 318 : /**
 319 :  * Define Rcpp Module to expose stan_fit's functions to R.
 320 :  */
 321 : RCPP_MODULE(stan_fit4model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_mod){
 322 :   Rcpp::class_<rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1,
 323 :                boost::random::ecuyer1988> >("stan_fit4model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1")
 324 :     // .constructor<Rcpp::List>()
 325 :     .constructor<SEXP, SEXP, SEXP>()
 326 :     // .constructor<SEXP, SEXP>()
 327 :     .method("call_sampler",
 328 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::call_sampler)
 329 :     .method("param_names",
 330 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_names)
 331 :     .method("param_names_oi",
 332 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_names_oi)
 333 :     .method("param_fnames_oi",
 334 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_fnames_oi)
 335 :     .method("param_dims",
 336 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_dims)
 337 :     .method("param_dims_oi",
 338 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_dims_oi)
 339 :     .method("update_param_oi",
 340 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::update_param_oi)
 341 :     .method("param_oi_tidx",
 342 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::param_oi_tidx)
 343 :     .method("grad_log_prob",
 344 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::grad_log_prob)
 345 :     .method("log_prob",
 346 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::log_prob)
 347 :     .method("unconstrain_pars",
 348 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::unconstrain_pars)
 349 :     .method("constrain_pars",
 350 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::constrain_pars)
 351 :     .method("num_pars_unconstrained",
 352 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::num_pars_unconstrained)
 353 :     .method("unconstrained_param_names",
 354 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::unconstrained_param_names)
 355 :     .method("constrained_param_names",
 356 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::constrained_param_names)
 357 :     .method("standalone_gqs",
 358 :             &rstan::stan_fit<model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1_namespace::model4c435d41f63_73fc79f8b1915e8208c736914c86d1a1, boost::random::ecuyer1988>::standalone_gqs)
 359 :   ;
 360 : }
 361 : 
 362 : // declarations
 363 : extern "C" {
 364 : SEXP file4c4373919d9( ) ;
 365 : }
 366 : 
 367 : // definition
 368 : 
 369 : SEXP file4c4373919d9(  ){
 370 :  return Rcpp::wrap("73fc79f8b1915e8208c736914c86d1a1");
 371 : }
 372 : 
 373 : 
Compilation argument:
 C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file4c4373919d9.cpp 2> file4c4373919d9.cpp.err.txt 
Warning message:
In system(cmd) : 'make' not found
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'file4c4373919d9.cpp.err.txt': No such file or directory

This is a RTools problem. Have you run

pkgbuild::has_build_tools(debug = TRUE)

?

pkgbuild::has_build_tools(debug = TRUE)

Scanning R CMD config CC…
cc_path:
‘’ does not exist
Scanning path…
Scanning registry…
Found C:/rtools40 for 4.0
[1] TRUE

Same output when I try the line:

m2 <- brm(f2 + f3 + set_rescor(FALSE), data = dat, cores = 4)

Compiling the C++ model
Error in file(con, "r") : cannot open the connection
In addition: Warning messages:
1: Rows containing NAs were excluded from the model. 
2: In system(cmd, intern = !verbose) :
  running command 'C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file4c4679c225a.cpp 2> file4c4679c225a.cpp.err.txt' had status 1
3: In file(con, "r") :
  cannot open file 'file4c4679c225a.cpp.err.txt': No such file or directory
Error in sink(type = "output") : invalid connection

What are

Sys.getenv("RTOOLS40_HOME")

and

Sys.getenv("PATH")

?

Actually I dont know where you took it from, but when googling i, seem like R tools are not being detected in R:

Should I try to reinstall Rtools?
https://cran.r-project.org/bin/windows/Rtools/

Problem solved when reinstalled Rtools. Many thanks for your support