I managed to spend yesterday getting the Rcpp hello
world installed again, but then it took hours for
me to track down a build bug vs. Stan that turned
out to be because they're defining a macro PI (at
least I think that's what's going on) that's messing
with the C++ parser when it sees stan::math::PI being
defined. I'm about to commit a patch to Stan that
will get rid of that constant.
Today, I installed the latest R (2.14) and latest
Rcpp (0.9.10) at work, and I can't get the Rcpp
hello world example to compile. Yet everything
worked just dandy when I did the same thing last
night at home.
This is all starting from
* fresh install of R 2.14
* fresh install.packages('Rcpp') of Rcpp 0.9.10
All I'm doing is following the breadcrumbs I left
last time I slogged through this (stan/doc/notes/rcpp.txt)
and get stalled at:
R
> setwd('temp')
> install.packages('Rcpp') // should get Rcpp_0.9.6.tgz
> require('Rcpp') // should load Rcpp
> Rcpp.package.skeleton(name='mypkg',module=TRUE)
// creates temp/mykg
SHELL
$ R CMD build mypkg // creates temp/mypkg_1.0.tar.gz
$ R CMD check mypkg // OK, with some warnings
It's no longer OK with some warnings, but rather
tells me:
=========================================================
~/stan> R CMD build mypkg
* checking for file �mypkg/DESCRIPTION� ... OK
* preparing �mypkg�:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building �mypkg_1.0.tar.gz�
~/stan> R CMD check mypkg
* using log directory �/Users/carp/stan/mypkg.Rcheck�
* using R version 2.14.2 (2012-02-29)
* using platform: x86_64-apple-darwin9.8.0 (64-bit)
* using session charset: UTF-8
* checking for file �mypkg/DESCRIPTION� ... OK
* checking extension type ... Package
* this is package �mypkg� version �1.0�
* checking package namespace information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking if there is a namespace ... OK
* checking for executable files ... OK
* checking whether package �mypkg� can be installed ... ERROR
Installation failed.
See �/Users/carp/stan/mypkg.Rcheck/00install.out� for details.
~/stan> cat /Users/carp/stan/mypkg.Rcheck/00install.out
* installing *source* package �mypkg� ...
** libs
*** arch - i386
g++ -arch i386 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/i386
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
-fPIC -g -O2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -arch i386 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/i386
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
-fPIC -g -O2 -c rcpp_module.cpp -o rcpp_module.o
g++ -arch i386 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o mypkg.so rcpp_hello_world.o rcpp_module.o
/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/lib/i386/libRcpp.a
-F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundation
ld: warning: in /usr/local/lib/libstdc++.dylib, file was built for
unsupported file format which is not the architecture being linked (i386)
installing to /Users/carp/stan/mypkg.Rcheck/mypkg/libs/i386
*** arch - x86_64
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
-fPIC -g -O2 -c rcpp_hello_world.cpp -o rcpp_hello_world.o
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64
-I/usr/local/include
-I"/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/include"
-fPIC -g -O2 -c rcpp_module.cpp -o rcpp_module.o
g++ -arch x86_64 -dynamiclib -Wl,-headerpad_max_install_names -undefined
dynamic_lookup -single_module -multiply_defined suppress
-L/usr/local/lib -o mypkg.so rcpp_hello_world.o rcpp_module.o
/Library/Frameworks/R.framework/Versions/2.14/Resources/library/Rcpp/lib/x86_64/libRcpp.a
-F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework
-Wl,CoreFoundation
installing to /Users/carp/stan/mypkg.Rcheck/mypkg/libs/x86_64
** R
** preparing package for lazy loading
** help
Warning: /Users/carp/stan/mypkg/man/mypkg-package.Rd:30: All text must
be in a section
*** installing help indices
** building package indices ...
** testing if installed package can be loaded
*** arch - i386
*** arch - x86_64
R(1222) malloc: *** error for object 0x7fff704bd500: pointer being freed
was not allocated
*** set a breakpoint in malloc_error_break to debug
sh: line 1: 1222 Abort trap
'/Library/Frameworks/R.framework/Resources/bin/R' --arch=x86_64
--no-save --slave <
/var/folders/ju/juD0VflHENew03RUV+bbPU+++TM/-Tmp-//RtmpRJ7Xbd/file47a4ecefc40
ERROR: loading failed for �x86_64�
* removing �/Users/carp/stan/mypkg.Rcheck/mypkg�
~/stan> R --version
R version 2.14.2 (2012-02-29)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License version 2.
For more information about these matters see
http://www.gnu.org/licenses/.
===============================================================
And I don't know if it's relevant, because I don't see any compiler
called out in the dump, but
==============================
~/stan> g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
===============================
- Bob
The weird thing is that it works on my Macbook Air, just
not on the iMac. Both are running the same Snow Leopard version
of the OS (the current is "Lion" -- these names are just too
cutesy for me). I'll have to check on versions of g++.
I also got some pointers from Dirk Eddelbuettel and others
on the list. They suggested I compile my own version of Rcpp.
Somehow using install.packages() may have messed things up.
(Though that's also what I did at home, and the non-module
Rcpp thing still works.)
- Bob
Thanks. Some of those docs are on the CRAN page, too.
I have the cheat sheet. What I need is a more thorough
Rcpp API doc.
What I don't see how to do is get the row-major sequence
of values corresponding to an R multi-dimensional array.
- Bob
Exactly. There's a proto-implementation of
var_context in the rstan subdirectory of Stan.
I figured out how to get the dimensions, but I
can't see how to get the values for a 3+ dimensional
array in R. I haven't looked that hard, yet.
Instead, I'm working on the manual, so I can
at least feel like I'm making progress. Every time
I touch R, Windows, Linux, a new gcc, etc. etc., it
feels like two steps back.
- Bob
What I don't see how to do is get the row-major sequence
of values corresponding to an R multi-dimensional array.
If users declare a Stan variable as
double x[I,J,K];
then it's going to need to be initialized from
a 3-D array from R. All I need from R are
the dimensions (that's in the example that Malecki
helped me write) and the values in last-index-major
order. Stan will do all the rest with the var_context
automatically.
- Bob
I knew that. We discussed this before and that's why
I set up var_context the way I did, anticipating reading
in from R (and R-style dump files).
Right -- I just need to figure out how to get
that array. I didn't see it in the Rcpp doc,
but it must be there somewhere.
- Bob
If users declare a Stan variable as
double x[I,J,K];
then it's going to need to be initialized from
a 3-D array from R. All I need from R are
the dimensions (that's in the example that Malecki
helped me write) and the values in last-index-major
order. Stan will do all the rest with the var_context
automatically.
Nice example -- that's exactly the order I meant.
I called it "last-index major" to parallel column major
in matrices. Is there a way to say that more idiomatically
in R? I don't recall ever hearing "shelf" before, but it
sort of corresponds to how R prints it out.
> If so, then
>
> c(apply(myarray, MARGIN = 1:2, FUN = function(x) x))
Cool. I don't think I'll ever understand R. That
looks like you're applying an identity function.
- Bob
Also, I thought we had decided to use "real", not "double"?
A
You're definitely the first guinea pig in line for
testing the R interface.
> Also, I thought we had decided to use "real", not "double"?
Sorry, yes, it's "real". I told you
I'd have trouble with it because it doesn't
match other programming languages!
Don't worry, it's right in the doc! That,
I can check automatically.
- Bob