Dealing with R 4.0

Sys.which(“make”)
make
“C:\rtools40\usr\bin\make.exe”
Sys.which(“g++”)
g++
“C:\rtools40\mingw64\bin\G__~1.EXE”

Those both look fine.

One more thing you can try to help us debug.

This requires the processx package. It should be easy to install.

path_to_file <- file.path(tempdir(), "file450474a25b88.cpp")
processx::run(command = "R", args = c("CMD", "SHLIB", path_to_file))

I am not sure why does R try to call with C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file1b10bff1325.cpp 2> file1b10bff1325.cpp.err.txt where the path is not full. @andrjohns do you have an idea?

EDIT: typos

Can you run Sys.getenv("PATH") and post the output again?

Also, can you restart R and run:

mod = "data{real y_mean;}parameters{real y;}model{y~normal(y_mean,1);}"
test = rstan::stan(model_code = mod,data=list(y_mean=0),verbose = TRUE)

And post the line that starts with error:?

1 Like

@rok_cesnovar: Not sure if I’m doing it right, but I added a comma (and explicit arguments) to the function in order to make it work. But I’m getting another error, even with that edit.

processx::run(command = “R”, args = c(“CMD”, “SHLIB”, path_to_file))
Error in processx::run(command = “R”, args = c(“CMD”, “SHLIB”, path_to_file)) :
System command ‘R’ failed, exit status: 1, stderr:
E> make: *** No rule to make target ‘C:\Users\REVSB00E\AppData\Local\Temp\RtmpWYG1O7/file450474a25b88.o’, needed by ‘C:\Users\REVSB00E\AppData\Local\Temp\RtmpWYG1O7/file450474a25b88.dll’. Stop.

@andrjohns:

Sys.getenv(“PATH”)
[1] “C:\rtools40\usr\bin;C:\Program Files\R\R-4.0.2\bin\x64;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Java\jre1.8.0_211\bin;C:\Program Files (x86)\Java\jre1.8.0_211\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn\;C:\Program Files\PuTTY\;C:\rtools40\usr\bin;C:\rtools40\mingw64\bin;C:\Program Files\Git\cmd;C:\Users\REVSB00E\AppData\Local\Microsoft\WindowsApps;C:\Users\REVSB00E\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;”

Regarding the second request: I don’t have any line in the C++ code that starts with error: The only error is the R one: file(con, "r") : cannot open the connection...

1 Like

Hmmm can you post full output from the command? There might be a clue in there

Sorry, having some problems including the output. But I’ve pasted it into this txt: stanOutput.txt (17.5 KB)

That’s a very odd one. The relevant issue is:

Compilation argument:
 C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file3c185abb4ca1.cpp 2> file3c185abb4ca1.cpp.err.txt 
Error in file(con, "r") : cannot open the connection
2: In file(con, "r") :
  cannot open file 'file3c185abb4ca1.cpp.err.txt': No such file or directory

And I can’t tell why it’s failing at that stage. @bgoodri Is this something you’ve seen before?

What output do you get from:

system("touch foo.cpp; R CMD SHLIB foo.cpp")

?

system(“touch foo.cpp; R CMD SHLIB foo.cpp”)
[1] 0

Oh sorry, that should have been two commands:

system("touch foo.cpp")
system("R CMD SHLIB foo.cpp")
1 Like

Hi

I’m (still also) having issues, that are seemingly identical to those reported by Esben
(originally reported back in the tread: Profile - hpjfromdk - The Stan Forums)

When executing a fit of the eight scools example

fit ← rstan::stan(file = file.path(“D:/R/$_R_Install/Stan”,“schools.stan”), data = schools_dat,verbose = TRUE)

I get (abriveated):

TRANSLATING MODEL ‘schools’ FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model ‘schools’.
COMPILING THE C++ CODE FOR MODEL ‘schools’ NOW.
OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.5; inline: 0.3.15

setting environment variables:
LOCAL_LIBS = “C:/Users/myusername/Documents/R/win-library/4.0/rstan/lib/x64/libStanServices.a” -L"C:/Users/myusername/Documents/R/win-library/4.0/StanHeaders/libs/x64" -lStanHeaders -L"C:/Users/myusername/Documents/R/win-library/4.0/RcppParallel/lib/x64" -ltbb
PKG_CPPFLAGS = -I"C:/Users/myusername/Documents/R/win-library/4.0/Rcpp/include/" -I"C:/Users/myusername/Documents/R/win-library/4.0/RcppEigen/include/" -I"C:/Users/myusername/Documents/R/win-library/4.0/RcppEigen/include/unsupported" -I"C:/Users/myusername/Documents/R/win-library/4.0/BH/include" -I"C:/Users/myusername/Documents/R/win-library/4.0/StanHeaders/include/src/" -I"C:/Users/myusername/Documents/R/win-library/4.0/StanHeaders/include/" -I"C:/Users/myusername/Documents/R/win-library/4.0/RcppParallel/include/" -I"C:/Users/myusername/Documents/R/win-library/4.0/rstan/include" -DEIGEN_NO_DEBUG -DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP -DSTAN_THREADS -DBOOST_NO_AUTO_PTR -include “C:/Users/myusername/Documents/R/win-library/4.0/StanHeaders/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 : 
   6 : // user includes
   7 : #include <Rcpp.h>
   8 : #include <rstan/io/rlist_ref_var_context.hpp>
   9 : #include <rstan/io/r_ostream.hpp>
  10 : #include <rstan/stan_args.hpp>
  11 : #include <boost/integer/integer_log2.hpp>
  12 : // Code generated by Stan version 2.21.0
  13 : 
  14 : #include <stan/model/model_header.hpp>
....
 540 : 
 541 : // definition
 542 : 
 543 : SEXP file4b2c1d4b6984(  ){
 544 :  return Rcpp::wrap("schools");
 545 : }
 546 : 
 547 : 
Compilation argument:
 C:/R/R-40~1.2/bin/x64/R CMD SHLIB file4b2c6abe7f40.cpp 2> file4b2c6abe7f40.cpp.err.txt 
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
  cannot open file 'file4b2c1d4b6984.cpp.err.txt': No such file or directory

The same happens when running: example(stan_model, package = “rstan”, run.dontrun = TRUE)
…which ends with:
Compilation argument:
C:/R/R-40~1.2/bin/x64/R CMD SHLIB file4b2c3a537912.cpp 2> file4b2c3a537912.cpp.err.txt
Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘file4b2c3a537912.cpp.err.txt’: No such file or directory

Finally, running:

fx ← inline::cxxfunction( signature(x = “integer”, y = “numeric” ) , “return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;” )

yields another similar output:

Error in file(con, “r”) : cannot open the connection
In addition: Warning message:
In file(con, “r”) :
cannot open file ‘file4b2c3f7f6304.cpp.err.txt’: No such file or directory

In all cases the cpp files file4b2c6abe7f40.cpp, file4b2c3a537912.cpp and file4b2c3f7f6304.cpp,
respectively subsequently exist in my C:\Users\myusername\AppData\Local\Temp\Rtmpm0Yagl folder

I have put the full output along with setup/session info in the file RSToutputs.txt (45.8 KB)

One thing that occured to me is the line: OS: x86_64, mingw32; rstan: 2.21.2; Rcpp: 1.0.5; inline: 0.3.15
should that actually not show mingw64 instaed of mingw32 ??

br/hpj

Can you run:

system("touch foo.cpp")
system("R CMD SHLIB foo.cpp")

And post the output?

system(“touch foo.cpp”)
[1] 0

system(“R CMD SHLIB foo.cpp”)
RSToutput01.txt (19.6 KB)

Yes

Can you post more of the output with that example? Specifically the part that has the string error: (with the colon)?

Can you post more of the output with that example? Specifically the part that has the string error: (with the colon)?

All output is include in the file RSToutputs.txt posted an hour ago above
There is no “error:” in the output as far as I can see…

That file just has sessionInfo. When you call

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

there should be

Loading required package: StanHeaders
Loading required package: ggplot2
rstan (Version 2.21.2, 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)
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 ‘16a540c6086086816528e4524def24d9’ FROM Stan CODE TO C++ CODE NOW.
successful in parsing the Stan model ‘16a540c6086086816528e4524def24d9’.
COMPILING THE C++ CODE FOR MODEL ‘16a540c6086086816528e4524def24d9’ NOW.

Compilation argument:

error: …

not quite…
the file starts with session info, and content of the setup files…

After that follows an output dump with a fit of the 8scools example (lines 52-615),
the example(stan_model, package = “rstan”, run.dontrun = TRUE) (lines 631-1023)
and finally > fx <- inline::cxxfunction( signature(x = “integer”, y = “numeric” ) ,
“return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;” ) (lines 1038-1043)

In neither of the examples I can find any “colon:”, however…

/hpj

Here is another dump of the out from:
example(stan_model, package = "rstan", run.dontrun = TRUE)

Run_StanFit_Example.txt (17.4 KB)

/hpj

I’ve been facing a similar problem by the looks of it. I recently got a new laptop so I thought it could be the new code I was working on but everything that I was able to run with rstan on the old laptop, seem to give the same error:

Error in file(con, “r”) : cannot open the connection
In addition: Warning messages:
1: In system(paste(CXX, ARGS), ignore.stdout = TRUE, ignore.stderr = TRUE) :
‘-E’ not found
2: In system(cmd, intern = !verbose) :
running command ‘C:/PROGRA~1/R/R-40~1.2/bin/x64/R CMD SHLIB file5438413746b7.cpp 2> file5438413746b7.cpp.err.txt’ had status 1
3: In file(con, “r”) :
cannot open file ‘file5438413746b7.cpp.err.txt’: No such file or directory
Error in sink(type = “output”) : invalid connection

My R.Version is:

R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

When I run:

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

I get the following result:
rstan.txt (21.1 KB)

Any help would be greatly appreciated!

1 Like