stan-dev / rstan

RStan, the R interface to Stan
https://mc-stan.org
1.04k stars 265 forks source link

Debug Error in file(con, "r"): cannot open the connection private$.run() #584

Open Jinghaoma opened 5 years ago

Jinghaoma commented 5 years ago

hello

Summary:

Wrong when calling rstan with Jamovi

Description:

I am trying to develop jamavi's modules with rstan. But when I used the module in jamovi, I got an error:

Debug Error in file(con, "r"): cannot open the connection private$.run() stan_model(model_code = mode) cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"", model_name, "\");", sep = ""), includes = inc, plugin = "rstan", save_dso = sav pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose)) withr::with_path(rtools_path(), code) force(code) cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose) compileCode(f, code, language = language, verbose = verbose) readLines(errfile) file(con, "r")

Screenshot

I tried to ask the developer of jamovi, but the developer of jamovi did not find the reason why stan throws this error. So I would like to ask the developer of stan how to solve this error.

My English is not very good, so I sent this post with Google Translate. There may be places that are difficult to understand. sorry.

Reproducible Steps:

I uploaded the jamovi module and development files to my Google Cloud. module .stan file development files

I want to reproduce this error by installing a .jmo file in jamovi.

Expected Output:

post-warmup draws per chain=25000, total post-warmup draws=1e+05.

          mean se_mean   sd    2.5%     25%     50%     75%   97.5% n_eff Rhat

mu1 20.66 0.00 1.28 18.14 19.82 20.66 21.50 23.18 94333 1 mu2 16.96 0.01 1.60 13.81 15.91 16.95 18.02 20.11 96909 1 sigma1 6.91 0.00 0.96 5.35 6.23 6.81 7.48 9.08 85519 1 sigma2 8.65 0.00 1.21 6.67 7.80 8.52 9.35 11.41 83641 1 delta 3.70 0.01 2.04 -0.34 2.34 3.70 5.06 7.72 95973 1 delta_over 0.96 0.00 0.19 0.00 1.00 1.00 1.00 1.00 78298 1 lp__ -147.07 0.01 1.46 -150.75 -147.78 -146.73 -145.99 -145.26 47127 1

Samples were drawn using NUTS(diag_e) at Tue Nov 06 23:14:54 2018. For each parameter, n_eff is a crude measure of effective sample size, and Rhat is the potential scale reduction factor on split chains (at convergence, Rhat=1).

RStan Version:

packageVersion("rstan") [1] ‘2.18.1’

R Version:

R.version.string [1] "R version 3.5.1 (2018-07-02)"

Operating System:

windows10: 17134.345 Jamovi: jamovi-0.9.5.8-win64

Thank you Jinghao

jonathon-love commented 5 years ago

hi rstan folks,

a jamovi dev here. we bundle a build of R with jamovi, and run analyses from many packages with it. it appears that rstan assumes something which isn't true in the case of R inside jamovi, but i'm not sure what it is. could you guys shed some light on it?

with thanks

bgoodri commented 5 years ago

Can someone with jamovi try it with rstan 2.18.2 from CRAN and specify the verbose = TRUE argument to stan() or sampling()?

On Sun, Nov 11, 2018 at 1:46 AM Jonathon Love notifications@github.com wrote:

hi rstan folks,

a jamovi dev here. we bundle a build of R with jamovi https://www.jamovi.org, and run analyses from many packages with it. it appears that rstan assumes something which isn't true in the case of R inside jamovi, but i'm not sure what it is. could you guys shed some light on it?

with thanks

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/stan-dev/rstan/issues/584#issuecomment-437647753, or mute the thread https://github.com/notifications/unsubscribe-auth/ADOrqm5CwWp9Iadx7HtJct7jf0HYjfb6ks5ut8fVgaJpZM4YYWJy .

jonathon-love commented 5 years ago

here's the output, the whole thing, or abridged:

TRANSLATING MODEL '7c2c0c530925eae2265e7121e1b92f6d' FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model '7c2c0c530925eae2265e7121e1b92f6d'.
OS: x86_64, mingw32; rstan: 2.18.2; Rcpp: 0.12.19; inline: 0.3.15
 >> setting environment variables:
PKG_LIBS =  -L"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/libs/x64" -lStanHeaders
PKG_CPPFLAGS =   -I"C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/library/Rcpp/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/RcppEigen/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/RcppEigen/include/unsupported"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/BH/include" -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/include/src/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -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// Code generated by Stan version 2.18.0
   7 :
   8 : #include <stan/model/model_header.hpp>
   9 :
  10 : namespace modelcd423434754_7c2c0c530925eae2265e7121e1b92f6d_namespace {
  11 :

<snip>

 546 :
 547 : // declarations
 548 : extern "C" {
 549 : SEXP filecd453692790( ) ;
 550 : }
 551 :
 552 : // definition
 553 :
 554 : SEXP filecd453692790(  ){
 555 :  return Rcpp::wrap("7c2c0c530925eae2265e7121e1b92f6d");
 556 : }
 557 :
 558 :
Compilation argument:
 C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/bin/x64/R CMD SHLIB filecd453692790.cpp 2> filecd453692790.cpp.err.txt

and the stacktrace:

stan(model_code = mode, data = stan_data, iter = 27000, warmup = 2000, chains = 1, cores = 1, verbose = T)
stan_model(file, model_name = model_name, model_code = model_code, stanc_ret = NULL, boost_lib = boost_lib, eigen_lib = eigen_lib, save_dso = save_dso, verbose = verbose)
cxxfunctionplus(signature(), body = paste(" return Rcpp::wrap(\"", model_name, "\");", sep = ""), includes = inc, plugin = "rstan", save_dso = save_dso | auto_write, module_name = paste("stan_fit4", model_cppname, "_mod", sep = ""), verbose = verbose)
pkgbuild::with_build_tools(cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose), required = rstan_options("required") && !identical(Sys.getenv("WINDOWS"), "TRUE") && !identical(Sys.getenv("R_PACKAGE_SOURCE"), ""))
withr::with_path(rtools_path(), code)
force(code)
cxxfunction(sig = sig, body = body, plugin = plugin, includes = includes, settings = settings, ..., verbose = verbose)
compileCode(f, code, language = language, verbose = verbose)
readLines(errfile)
file(con, "r")

i gather an error is occurring, and the error is supposed to be written to filecd453692790.cpp.err.txt, but it isn't. if i look in my temp dir, the filecd453692790.cpp file is there, but not the error file.

with thanks

jonathon

jonathon-love commented 5 years ago

if i run the command manually (having set the environmental variables):

C:\Users\jonathon\AppData\Local\Temp>C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/bin/x64/R CMD SHLIB filecd453692790.cpp

i get:

C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/etc/x64/Makeconf:230: warning: overriding recipe for target '.m.o'
C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/etc/x64/Makeconf:223: warning: ignoring old recipe for target '.m.o'
c:/Rtools/mingw_64/bin/g++  -I"C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/include" -DNDEBUG -I"C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/library/Rcpp/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/RcppEigen/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/RcppEigen/include/unsupported"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/BH/include" -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/include/src/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/include/"  -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/rstan/include" -DEIGEN_NO_DEBUG  -DBOOST_DISABLE_ASSERTS -std=c++1y    -I"d:/Compiler/gcc-4.9.3/local330/include"     -O2 -Wall  -mtune=core2 -c filecd453692790.cpp -o filecd453692790.o
filecd453692790.cpp:8:39: fatal error: stan/model/model_header.hpp: No such file or directory
 #include <stan/model/model_header.hpp>
                                       ^
compilation terminated.
C:/Users/jonathon/Downloads/jamovi-0.9.5.8-win64/Frameworks/R/etc/x64/Makeconf:215: recipe for target 'filecd453692790.o' failed
make: *** [filecd453692790.o] Error 1

which doesn't make any sense, because C:\Users\jonathon\AppData\Roaming\jamovi\modules\learn\R\StanHeaders\include\src\stan\model contains model_header.hpp, and -I"C:/Users/jonathon/AppData/Roaming/jamovi/modules/learn/R/StanHeaders/include/src/" is clearly specified as an argument.

any ideas as to what the issue could be?

with thanks

bgoodri commented 5 years ago

I agree it doesn't make sense. Can you try R CMD SHLIB filecd453692790.cpp after creating a Makevars.win file in the same directory that just contains

LOCAL_CPPFLAGS = -v -H

in order for it to be verbose about what includes it is trying to do.

jonathon-love commented 5 years ago

ah! i figured it out. it turns out the error in compilation was a red herring. it looks like an older Rtools was being used. once i updated that, it would compile fine from the terminal.

jonathon-love commented 5 years ago

it turns out the issue was that C:\Windows\System32 was not on the path, and when R invokes the compiler, it begins by calling cmd.exe. it's unsual that being unable to execute the compiler because cmd.exe is missing, fails silently.

Jinghaoma commented 5 years ago

Sorry, I didn't help anything.

Although I don't understand what you are talking about at all, it seems that the problem is solved. Pay tribute to the two developers. thank you very much

Jinghao