3

I need to install Rstan for a data analysis class. The instructions are posted here http://code.google.com/p/stan/wiki/RStanGettingStarted. I'm running Mac OS 10.5.8 and R 2.15.1 GUI 1.52 Leopard build 32-bit (6188). I just installed Xcode version 3.1.4, the Xcode c++ compiler that is compatible with leopard (I had to get a mac developer account to do this).

Per the Stan installation instruction, I entered the following code to see if my compiler was working:

library(inline) 
library(Rcpp)
src <- ' 
  std::vector<std::string> s; 
  s.push_back("hello");
  s.push_back("world");
  return Rcpp::wrap(s);
'
hellofun <- cxxfunction(body = src, includes = '', plugin = 'Rcpp', verbose = FALSE)
cat(hellofun(), '\n') 

It returns the following error:

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! 
Library/Frameworks/R.framework/Versions/2.15/Resources/library/
Rcpp/include/Rcpp/internal/export.h: In function ‘void
Rcpp::internal::export_range__dispatch(SEXPREC*, InputIterator,
Rcpp::traits::r_type_primitive_tag)’:
/Library/Frameworks/R.framework/Versions/2.15/Resources/
library/Rcpp/include/Rcpp/internal/export.h:56: internal
compiler error: Bus error
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://developer.apple.com/bugreporter> for
instructions.
make: *** [file795214e66510.o] Error 1
In addition: Warning message:
running command '/Library/Frameworks/R.framework/Resources/bin/
R CMD SHLIB file795214e66510.cpp 2>
file795214e66510.cpp.err.txt' had status 1

When I try to install stan:

 install.packages('rstan', type = 'source') ] 

I get this warning: Warning message: In install.packages("rstan", type = "source") : installation of package ‘rstan’ had non-zero exit status

I have no idea how C++ works. All of my coding experience is in R and has not before required compiling into C++. I've been trying really hard to figure out what's wrong for the last 4 hours or so, googling these error messages over and over without much luck. Any help would be greatly appreciated and would also help about 10 other students in my class who are having identical or analogous problems. Thank you very, very much.

tom field
  • 31
  • 1
  • 2
  • You do not mention which c++ compiler you installed, which version of Rcpp, and you do not mention installing the recommended FORTRAN compiler, either. I am no longer running 10.5.8 and have upgraded to the XCode package for 10.6.8. In this environment that code runs without error using Rcpp version: 0.9.14. Generally such questions are best submitted to the Mac-SIG mailing list, although Simon Urbanel has been seen in SO occasionally. – IRTFM Oct 05 '12 at 23:55
  • I mentioned that the C++ compiler I'm using is Xcode 3.1.4. Rcpp version is whatever was current today. I don't know anything about the recommended FORTRAN compiler, so would like to know more. – tom field Oct 06 '12 at 00:41
  • 1
    Rcpp users on OS X have had troubles because of the messy situation with Apple and the FSF fighting over gcc copyrights---but Rcpp per se works as seen by the CRAN tests etc. You may "simply" need to install the compilers provided by Simon for OS X and R via his site. As for Stan, the developers have not been all that forthcoming with details so I will have to direct you to their list for all aspects pertaining to (R)Stan. – Dirk Eddelbuettel Oct 06 '12 at 00:43
  • XCode is not the name of the MacOS Cpp compiler. It is the name of the development environment. The "Tools" page at the att.research.com webpage says "Make sure gcc-4.2 is selected during the installation (default in recent Xcode versions)." I do not know whether the Leopard version of Xcode is considered 'recent'. – IRTFM Oct 06 '12 at 15:21
  • I might have answered this on October 15th here, not having seen your question, although I am running a Windows machine: http://stackoverflow.com/questions/12848168/will-rstan-run-on-a-supercomputer Even though you are running a Mac maybe the Windows instructions I posted at the link above will be of some help. – Mark Miller Oct 19 '12 at 18:04
  • I think you're looking for: https://groups.google.com/forum/?fromgroups#!forum/stan-users – Ben Bolker Oct 19 '12 at 20:31
  • Dirk: When you say we [the Stan developers] "have not been all that forthcoming with details", what kind of details would you like to see? RStan works out of the box with the versions of R, Rcpp and C++ compilers advertised on the RStan install page. The most recent release of Rcpp (0.10.1) broken RcppEigen (see http://dirk.eddelbuettel.com/blog/2012/11/27/ ), so RStan no longer works with the latest Rcpp. We're removing the RcppEigen dependency in the next release to avoid this problem in the future. – Bob Carpenter Dec 11 '12 at 21:42

2 Answers2

5

This looks to me like an issue with the installation of your C++ compiler or with your installation of the Rcpp package, rather than an issue with the rstan package. However, if g++ is causing an intractable problem for you, an alternative is the clang compiler, which should work with Rcpp and rstan if you create $HOME/.R/Makevars with these two lines

CC=clang

CXX=clang++

Austin Henley
  • 4,625
  • 13
  • 45
  • 80
Ben Goodrich
  • 4,870
  • 1
  • 19
  • 18
2

As mentioned in another answer, the first step is to get Rcpp working on your Mac (i.e,. at least pass the hello world example).

A similar issue for Rcpp previously: https://stat.ethz.ch/pipermail/r-sig-mac/2010-July/007574.html

In addition, from this webpage http://useyourloaf.com/blog/2011/03/21/compiler-options-in-xcode-gcc-or-llvm.html, it seems that gcc 4.2 and 4.0 are both in Xcode 3.14 (not sure as it does not say it's 3.14). So try to make sure gcc 4.2.1 is used by R is important. Executing the following in a terminal will show what is the current version of gcc.

$ g++ -v

J Guo
  • 23
  • 2