I am trying to use the mixl
package in R for discrete choice modelling. mixl
includes a pre-compiler that takes a model specification written in plain text, and converts it to a C++ utility function callable from R.
I run R in Windows 10. I have installed the Rtools
successfully and added the R executable path (C:\Program Files\R\R-3.6.1\bin) into the environment variables list.
find_rtools() [1] TRUE
install.Rtools(check = T) No need to install Rtools - You've got the relevant version of Rtools installed
I have installed the Rcpp
package but when running the following code
library(mixl)
data("Train", package = "mlogit")
Train$ID <- Train$id
Train$CHOICE <- as.numeric(Train$choice)
mixl_test <- "
ASC_B_RND <- @ASC_B + draw_1*@SIGMA_B;
TIME_A_RND <- @B_timeA + draw_2*@SIG_time;
TIME_B_RND <- @B_timeB + draw_2*@SIG_time;
U_PT <- @B_price*$price_A/1000 + TIME_A_RND*$time_A/60 + @B_change*$change_A;
U_Car <- ASC_B_RND + (@B_price*$price_B/1000 + TIME_B_RND*$time_B/60);
"
model_spec <- specify_model(mixl_test, Train)
the following error message comes up.
C:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.1/include" -DNDEBUG -I"C:/Users/takaa/Documents/R/win-library/3.6/mixl/include" -I"C:/Users/takaa/Documents/R/win-library/3.6/Rcpp/include" -I"C:/Users/takaa/AppData/Local/Temp/RtmpOks2bQ/sourceCpp-x86_64-w64-mingw32-1.0.2" -fopenmp -O2 -Wall -mtune=generic -c file2fbc33473a13.cpp -o file2fbc33473a13.o file2fbc33473a13.cpp: In function 'void utilityFunction(Rcpp::NumericVector, UF_args2&)': file2fbc33473a13.cpp:127:1: error: 'ASC_B_RND' was not declared in this scope ASC_B_RND <- ASC_B + draw[0]*SIGMA_B;
^
file2fbc33473a13.cpp:128:1: error: 'TIME_A_RND' was not declared in this scope TIME_A_RND <- B_timeA + draw[1]*SIG_time;
^
file2fbc33473a13.cpp:129:1: error: 'TIME_B_RND' was not declared in this scope TIME_B_RND <- B_timeB + draw[1]*SIG_time;
^
make: *** [C:/PROGRA~1/R/R-36~1.1/etc/x64/Makeconf:215: file2fbc33473a13.o] Error 1
Error in Rcpp::sourceCpp(code = e1$cpp_code, env = cpp_container) : Error 1 occurred building shared library.
I believe the questions is similar to [Error 1 occurred building shared library while sourcing cpp code inside R and [https://github.com/aidenlab/straw/issues/20][2] but I have rebooted Rstudio and Windows (and nothing changed) and concerning the second question should I change to -std=c++11
from -std=gnu++11
? Has Anyone faced a similar problem, what is the issue here?
R version 3.6.1 (2019-07-05) -- "Action of the Toes" Copyright (C) 2019 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 (64-bit)
Thank you!