Struggling with rstan installation

1,104 views
Skip to first unread message

Yvette Bonvalot

unread,
May 13, 2016, 3:40:40 PM5/13/16
to Stan users mailing list
Hello all,

My system is:
x86-64 machine (i7) - Windows 7 x64 - build 7601, Service Pack 1
R 3.3.0
RStudio Version 0.99.1172
RTools33

I am trying to install the lastest version of "rstan" (2.9.0-3) on my computer following instructions at https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started

Here is the code I ran in RStudio:

*************************************************************************************************************
# Lines of code to tun before installing rstan (as indicated in instructions):


# First set:
dotR
<- file.path(Sys.getenv("HOME"), ".R")
if (!file.exists(dotR)) dir.create(dotR)
M
<- file.path(dotR, "Makevars")
if (!file.exists(M)) file.create(M)
cat
("\nCXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function", file = M, sep = "\n", append = TRUE)


# Second set:
cat
('Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")', file = file.path(Sys.getenv("HOME"), ".Rprofile"), sep = "\n", append = TRUE)


# Test set:
cat
(readLines(M), sep = "\n")
cat
(M)


# Installing rstan:
install
.packages("rstan", dependencies = TRUE)

# If above line fails, do these 3 lines:
#    options(repos = "https://cran.r-project.org")
#    # omit the "s" if you cannot handle https downloads
#    install.packages("rstan", dependencies = TRUE)

# If all else fails, you can try to install rstan from source via
#    install.packages("rstan", type = "source")


And here is what I get:
---------------------------------------------------------------------------------------------------------------
> # Lines of code to tun before installing rstan:
> # First set:
> dotR <- file.path(Sys.getenv("HOME"), ".R")
> if (!file.exists(dotR)) dir.create(dotR)
> M <- file.path(dotR, "Makevars")
> if (!file.exists(M)) file.create(M)
> cat("\nCXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function", 
+     file = M, sep = "\n", append = TRUE)
> # Second set:
> cat('Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")',
+     file = file.path(Sys.getenv("HOME"), ".Rprofile"), 
+     sep = "\n", append = TRUE) 
> # Test set:
> cat(readLines(M), sep = "\n")

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function

CXXFLAGS=-O3 -Wno-unused-variable -Wno-unused-function
> cat(M)
C:/Users/Zef/Documents/.R/Makevars
> # Install RStan:
> install.packages("rstan", dependencies = TRUE)
Installing package into ‘C:/Users/Zef/R-Library’
(as ‘lib’ is unspecified)
Content type 'application/zip' length 3251255 bytes (3.1 MB)
downloaded 3.1 MB

package ‘rstan’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\Zef\AppData\Local\Temp\RtmpsfBEPb\downloaded_packages
> # If above line fails, do these 3 lines:
> #    options(repos = "https://cran.r-project.org")
> #    # omit the "s" if you cannot handle https downloads
> #    install.packages("rstan", dependencies = TRUE)
> # If all else fails, you can try to install rstan from source via
> #    install.packages("rstan", type = "source")
---------------------------------------------------------------------------------------------------------------

Thus until there, everything look OK.
Then I restart R and try to "Verify that your toolchain works by executing in R", running:
library(inline)
library
(rstan)
# As the startup message says, if you are using rstan locally on a multicore
# machine and have plenty of RAM to estimate your model in parallel, at this
# point execute the 2 next lines of code:
rstan_options
(auto_write = TRUE)
options
(mc.cores = parallel::detectCores())
# Then execute:
example
("cxxfunction", package = "inline", run.dontrun = TRUE)
And here is what I get:
cxxfnc> # default plugin
cxxfnc> fx <- cxxfunction( signature(x = "integer", y = "numeric" ) , '
cxxfnc+ 	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
cxxfnc+ ' )
Warning message:
running command 'make -f "C:/PROGRA~1/R/R-33~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.0/share/make/winshlib.mk" -f "C:/Users/Zef/Documents/.R/Makevars" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file136c30e779ff.dll" WIN=64 TCLBIN=64 OBJECTS="file136c30e779ff.o"' had status 127 

ERROR(s) during compilation: source code errors or compiler configuration errors!

Program source:
  1: 
  2: // includes from the plugin
  3: #include <R.h>
  4: #include <Rdefines.h>
  5: #include <R_ext/Error.h>
  6: 
  7: 
  8: // user includes
  9: 
 10: 
 11: // declarations
 12: extern "C" {
 13: SEXP file136c30e779ff( SEXP x, SEXP y) ;
 14: }
 15: 
 16: // definition
 17: 
 18: SEXP file136c30e779ff( SEXP x, SEXP y ){
 19: 
 20: 	return ScalarReal( INTEGER(x)[0] * REAL(y)[0] ) ;
 21:  
 22: Rf_warning("your C++ program does not return anything"); 
 23:  return R_NilValue ; 
 24: }
 25: 
 26: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! Warning message:
running command 'make -f "C:/PROGRA~1/R/R-33~1.0/etc/x64/Makeconf" -f "C:/PROGRA~1/R/R-33~1.0/share/make/winshlib.mk" -f "C:/Users/Zef/Documents/.R/Makevars" SHLIB_LDFLAGS='$(SHLIB_CXXLDFLAGS)' SHLIB_LD='$(SHLIB_CXXLD)' SHLIB="file136c30e779ff.dll" WIN=64 TCLBIN=64 OBJECTS="file136c30e779ff.o"' had status 127 
In addition: Warning message:
running command 'C:/PROGRA~1/R/R-33~1.0/bin/x64/R CMD SHLIB file136c30e779ff.cpp 2> file136c30e779ff.cpp.err.txt' had status 1 
> 

All the R packages have been updated. 
I also add two pathways (permanently) to my windows path environment variable: C:\RTools\bin;C:\RTools\gcc-4.6.3\bin
But no success.
Any idea ???

Ben Goodrich

unread,
May 13, 2016, 3:56:41 PM5/13/16
to Stan users mailing list
On Friday, May 13, 2016 at 3:40:40 PM UTC-4, Yvette Bonvalot wrote:
I also add two pathways (permanently) to my windows path environment variable: C:\RTools\bin;C:\RTools\gcc-4.6.3\bin
But no success.
Any idea ???
 
 R 3.3.0 only works with Rtools33. You either need to install and use R 3.2.x to use Rtools32 or uninstall Rtools32 and install Rtools33.

Ben

Yvette Bonvalot

unread,
May 13, 2016, 4:00:52 PM5/13/16
to stan-...@googlegroups.com
This is what I did.
I have R 3.3.0 and RTools33

--
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/MJXiDoFQ_Os/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Yvette Bonvalot

unread,
May 13, 2016, 4:05:48 PM5/13/16
to stan-...@googlegroups.com
But still does not work :(

Ben Goodrich

unread,
May 13, 2016, 4:34:33 PM5/13/16
to Stan users mailing list
On Friday, May 13, 2016 at 4:05:48 PM UTC-4, Yvette Bonvalot wrote:
But still does not work :(

What is your PATH environmental variable now? Before, you had it as C:\Rtools\gcc-4.6, which is for Rtools32.

Ben

Yvette Bonvalot

unread,
May 16, 2016, 12:43:36 PM5/16/16
to stan-...@googlegroups.com
Hi Ben,

Your indication on "C:\Rtools\gcc-4.6, which is for Rtools32" helped me to find why it was not working.
I installed R3.3.0 and RTools33 as indicated here https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows.

My mistakes / misunderstandings were that:
1) I did not select the option "Edit the system path" during RTools installation process
2) After selecting that option, the DOS pathways were adequately added BUT after that, I was trying to "Check if Rtools can be used in R" as indicated on the same github page, https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows. Nevertheless, the DOS Pathways results you get in R when using "Sys.getenv('PATH')" - as indicated below paragraph "Check if Rtools can be used in R" - are for RTools32 not for RTools33.

i.e., if RTools located in C:\RTools:
  • Using "rstan with R 2.x.y and RTools32 requires pathways "c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin"
  • Using "rstan with R 3.3.0 and RTools33 requires pathways "c:\Rtools\bin;c:\Rtools\mingw_64\bin"

Thanks a lot for having put me on the right track.
Have a great day :)


Yvette Bonvalot

unread,
Jun 2, 2016, 10:38:45 AM6/2/16
to stan-...@googlegroups.com
Hi again,

I am installing "rstan" on a virtual machine (i7, Win7, 64 bits).
I installed R 3.3.0 64 bits only and RTools33.exe (64 bits only).
PATH is in the attached file "PATH-VM.PNG".

Everything is fine until I try to run example 01, see error message in attached file "RunningExample01.PNG".

Could you help me please ?



PATH-VM.PNG
RunningExample01.PNG

Ben Goodrich

unread,
Jun 2, 2016, 10:53:01 AM6/2/16
to Stan users mailing list
On Thursday, June 2, 2016 at 10:38:45 AM UTC-4, Yvette Bonvalot wrote:
Everything is fine until I try to run example 01, see error message in attached file "RunningExample01.PNG".

Could you help me please ?

It looks like you have a partially installed rstan. To fix this, do

remove.packages("rstan")

and then make sure it is 100% gone with

system.file("libs", package = "rstan") # should return ""

If that last line yields something other than "", manually remove the entire rstan directory from Windows Explorer or whatever.

Then reinstall rstan with


install.packages("rstan", dependencies = TRUE)

Ben

Yvette Bonvalot

unread,
Jun 2, 2016, 11:15:05 AM6/2/16
to stan-...@googlegroups.com
Ben,

I tried to reinstall from scratch to get a clean VM image. And now I get the following error when trying to install STAN

--
ReInstallationIssue.PNG

Daniel Lee

unread,
Jun 2, 2016, 11:33:20 AM6/2/16
to stan-users mailing list
Hi Yvette,

Do you have a RTools installed properly? You need to install the version that matches the version of R that you have and you will need to put it on the path. See: https://github.com/stan-dev/rstan/wiki/Install-Rtools-for-Windows


Daniel


--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.

Yvette Bonvalot

unread,
Jun 2, 2016, 11:34:57 AM6/2/16
to stan-...@googlegroups.com
Yes I have R 3.3.0 and Rtools33.
And paths are ok.
PATH-VM.PNG

Yvette Bonvalot

unread,
Jun 2, 2016, 11:45:47 AM6/2/16
to stan-...@googlegroups.com
Working...
I had to reboot the VM.
Reply all
Reply to author
Forward
0 new messages