Dear Rcpp list,
It's time for me to finally try out Rcpp since I have to do some
computing for my research. Some questions (please be kind as I'm only
a beginner C programmer using .C() and not smart enough to understand .
Call()):
1. I plan to use objects like
Rcpp::NumericMatrix orig(matrix);
to store. To confirm, storing to orig directly stores into the
original R object matrix right?
orig(i,j) = some double;
2. int n = orig.rows();
Where can I find documentation on all the functions associated with
the class? I'd like to know all the available functions plus
information about it (for example, the above returns an int).
3. Is there a class for multidimensional arrays? I'm thinking of
array() in R. I use something like
S2[i + (*nObs)*j + (*nObs)*(*nParam)*k] = ...;
for all vectors, matrices, and arrays in C, and this is a pain as it
is a souce of a lot of my errors.
4. My original code is using nlm() in R to fit my model. However, I
think it is best to do the Newton-Raphson directly in C/C++. Can some
how evaluate matrix multiplication using "%*%" in R directly in my C++
code (using the Rcpp::NumericMatrix class)?
5. How do I return a list in R that consists of a value, vector, and
matrix? The three can be allocated in C++ or allocated prior to
entering C++ and passed on in .Call()?
6. How do I compile the .cpp file on the
command line? I got the following based on Dirk's HPC talk but
getting errors on my mac os x:
$ PKG_CPPFLAGS='r -e'Rcpp:::CxxFlags\(\)'' PKG_LIBS='r
-e'Rcpp:::LdFlags\(\)'' R CMD SHLIB rcpp.cpp
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include -fPIC -g -O2 -c rcpp.cpp
-o rcpp.o
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `g++ -arch x86_64
-I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include -fPIC -g -O2 -c rcpp.cpp
-o rcpp.o'
make: *** [rcpp.o] Error 2
If I get these things going then I'd be happy to release the code as
an example on using Rcpp to do maximization/model fitting.
Thanks.
Vinh
[Rcpp-devel] basic usage help
11 messages · Romain Francois, Davor Cubranic, Dirk Eddelbuettel +1 more
Le 26/05/10 18:55, Vinh Nguyen a ?crit :
Dear Rcpp list, It's time for me to finally try out Rcpp
Great. You won't regret it ;-)
since I have to do some computing for my research. Some questions (please be kind as I'm only a beginner C programmer using .C() and not smart enough to understand . Call()):
This is where Rcpp comes in. It will make you forget that .Call looks silly and complicated. .C seems easier, but that is an illusion.
1. I plan to use objects like Rcpp::NumericMatrix orig(matrix); to store. To confirm, storing to orig directly stores into the original R object matrix right? orig(i,j) = some double;
Yes. Rcpp classes of the new api (e.g. Rcpp::NumericMatrix) act as a wrapper. They change the way you look at the R object, but not the object itself. However, if you pass a SEXP that really is an integer matrix, Rcpp will cast it to a numeric matrix. see the thread : http://permalink.gmane.org/gmane.comp.lang.r.rcpp/369 for how that might byte you if you are not aware of it.
2. int n = orig.rows(); Where can I find documentation on all the functions associated with the class? I'd like to know all the available functions plus information about it (for example, the above returns an int).
Dirk maintains a this http://dirk.eddelbuettel.com/code/rcpp/html/index.html generated by doxygen. Some people like it. The issue with classes like NumericMatrix is that they are generated from a template and this makes it difficult for things like doxygen to produce something nice. (some people don't like it) One approximate way is to grep around the unit tests. We do have quite a good coverage and we try to stress each functionality of Rcpp. Otherwise the source code.
3. Is there a class for multidimensional arrays? I'm thinking of array() in R. I use something like S2[i + (*nObs)*j + (*nObs)*(*nParam)*k] = ...; for all vectors, matrices, and arrays in C, and this is a pain as it is a souce of a lot of my errors.
Not currently. Not that it is difficult to achieve, but it has to raise up on our list of priorities.
4. My original code is using nlm() in R to fit my model. However, I think it is best to do the Newton-Raphson directly in C/C++. Can some how evaluate matrix multiplication using "%*%" in R directly in my C++ code (using the Rcpp::NumericMatrix class)?
we don't currently have operators on Rcpp types. maybe some day. we however developped the RcppArmadillo package, which gives you the full power of armadillo (http://arma.sourceforge.net/) plus the convenience of Rcpp, at a small cost (see examples in RcppArmadillo)
5. How do I return a list in R that consists of a value, vector, and matrix? The three can be allocated in C++ or allocated prior to entering C++ and passed on in .Call()?
Something like this: using namespace Rcpp ; // for _ IntegerVector z(5) ; NumericMatrix foo( 3, 4 ); return List::create( _["x"] = 2, _["z"] = z, _["foo"] = foo ) ; You don't need to (but you can if you want) allocate things before. I told you .C was only easier by illusion ;-) In fact, with Rcpp you don't have to care too much about allocation, etc ... and you can concentrate on the problem you are trying to solve rather than fighting with the R API.
6. How do I compile the .cpp file on the command line? I got the following based on Dirk's HPC talk but getting errors on my mac os x:
The easiest way by far is to make a package and follow the guidelines of our last release notes. See the section "Using Rcpp in other packages" here http://romainfrancois.blog.free.fr/index.php?post/2010/05/17/Rcpp-0.8.0 The next easy way is to build on the smartness of the inline package. With verbose = TRUE, it will show you how to run the show: fx <- cppfunction( , "return R_NilValue ;", verbose = TRUE )
$ PKG_CPPFLAGS='r -e'Rcpp:::CxxFlags\(\)'' PKG_LIBS='r
-e'Rcpp:::LdFlags\(\)'' R CMD SHLIB rcpp.cpp
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include -fPIC -g -O2 -c rcpp.cpp
-o rcpp.o
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `g++ -arch x86_64
-I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include -fPIC -g -O2 -c rcpp.cpp
-o rcpp.o'
make: *** [rcpp.o] Error 2
If I get these things going then I'd be happy to release the code as
an example on using Rcpp to do maximization/model fitting.
We look forward to it.
Thanks. Vinh
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cork4b : highlight 0.1-8 |- http://bit.ly/bklUXt : RcppArmadillo 0.2.1 `- http://bit.ly/936ck2 : Rcpp 0.8.0
On Wed, May 26, 2010 at 10:21 AM, Romain Francois
<romain at r-enthusiasts.com> wrote:
Le 26/05/10 18:55, Vinh Nguyen a ?crit :
Dear Rcpp list, It's time for me to finally try out Rcpp
Great. You won't regret it ;-)
Thanks for the prompt response. My only initial hesitation about using Rcpp is the uncertainty in the availability of support and development in the future. I know .C() and .Call() will always be available so long as R is in business (and it looks like it will be around for the rest of my life!). I'm not an expert in programming so I'd hate to re-program things down the line. However, observing the vibe on the list and that Prof. Bates is also using it, I feel very relieved =]. Keep up the good work!
since I have to do some computing for my research. ?Some questions (please be kind as I'm only a beginner C programmer using .C() and not smart enough to understand . Call()):
This is where Rcpp comes in. It will make you forget that .Call looks silly and complicated. .C seems easier, but that is an illusion.
1. ?I plan to use objects like Rcpp::NumericMatrix orig(matrix); to store. ?To confirm, storing to orig directly stores into the original R object matrix right? orig(i,j) = some double;
Yes. Rcpp classes of the new api (e.g. Rcpp::NumericMatrix) act as a wrapper. They change the way you look at the R object, but not the object itself. However, if you pass a SEXP that really is an integer matrix, Rcpp will cast it to a numeric matrix. see the thread : http://permalink.gmane.org/gmane.comp.lang.r.rcpp/369 for how that might byte you if you are not aware of it.
2. ?int n = orig.rows(); Where can I find documentation on all the functions associated with the class? ?I'd like to know all the available functions plus information about it (for example, the above returns an int).
Dirk maintains a this http://dirk.eddelbuettel.com/code/rcpp/html/index.html generated by doxygen. Some people like it. The issue with classes like NumericMatrix is that they are generated from a template and this makes it difficult for things like doxygen to produce something nice. (some people don't like it)
Yea, don't see information on NumericMatrix or stuff from the "new" API.
One approximate way is to grep around the unit tests. We do have quite a good coverage and we try to stress each functionality of Rcpp. Otherwise the source code.
3. ?Is there a class for multidimensional arrays? ?I'm thinking of array() in R. ?I use something like S2[i + (*nObs)*j + (*nObs)*(*nParam)*k] = ...; for all vectors, matrices, and arrays in C, and this is a pain as it is a souce of a lot of my errors.
Not currently. Not that it is difficult to achieve, but it has to raise up on our list of priorities.
I'll stick to my single dimensional arrays then.
4. ?My original code is using nlm() in R to fit my model. However, I think it is best to do the Newton-Raphson directly in C/C++. ?Can some how evaluate matrix multiplication using "%*%" in R directly in my C++ code (using the Rcpp::NumericMatrix class)?
we don't currently have operators on Rcpp types. maybe some day. we however developped the RcppArmadillo package, which gives you the full power of armadillo (http://arma.sourceforge.net/) plus the convenience of Rcpp, at a small cost (see examples in RcppArmadillo)
At first I wanted to refrain from this since I didn't want to get too complex as I'm learning how to use Rcpp. However, after reviewing your recent example more thoroughly, it doesn't seem too complicated. To confirm, returning a colvec and matrix objects from arma is OK (R will understand)?
5. ?How do I return a list in R that consists of a value, vector, and matrix? ?The three can be allocated in C++ or allocated prior to entering C++ and passed on in .Call()?
Something like this: using namespace Rcpp ; // for _ IntegerVector z(5) ; NumericMatrix foo( 3, 4 ); return List::create( ? ? ? ?_["x"] = 2, ? ? ? ?_["z"] = z, ? ? ? ?_["foo"] = foo ) ; You don't need to (but you can if you want) allocate things before. I told you .C was only easier by illusion ;-) In fact, with Rcpp you don't have to care too much about allocation, etc ... and you can concentrate on the problem you are trying to solve rather than fighting with the R API.
6. ?How do I compile the .cpp file on the command line? ?I got the following based on Dirk's HPC talk but getting errors on my mac os x:
The easiest way by far is to make a package and follow the guidelines of our last release notes. See the section "Using Rcpp in other packages" here http://romainfrancois.blog.free.fr/index.php?post/2010/05/17/Rcpp-0.8.0 The next easy way is to build on the smartness of the inline package. With verbose = TRUE, it will show you how to run the show: fx <- cppfunction( , "return R_NilValue ;", verbose = TRUE )
Ahh I see.
$ PKG_CPPFLAGS='r -e'Rcpp:::CxxFlags\(\)'' PKG_LIBS='r
-e'Rcpp:::LdFlags\(\)'' R CMD SHLIB rcpp.cpp
g++ -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include ? ?-fPIC ?-g -O2 -c rcpp.cpp
-o rcpp.o
/bin/sh: -c: line 0: syntax error near unexpected token `('
/bin/sh: -c: line 0: `g++ -arch x86_64
-I/Library/Frameworks/R.framework/Resources/include
-I/Library/Frameworks/R.framework/Resources/include/x86_64 r
-eRcpp:::CxxFlags() -I/usr/local/include ? ?-fPIC ?-g -O2 -c rcpp.cpp
-o rcpp.o'
make: *** [rcpp.o] Error 2
If I get these things going then I'd be happy to release the code as
an example on using Rcpp to do maximization/model fitting.
We look forward to it.
Thanks. Vinh
-- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cork4b : highlight 0.1-8 |- http://bit.ly/bklUXt : RcppArmadillo 0.2.1 `- http://bit.ly/936ck2 : Rcpp 0.8.0
On Wed, May 26, 2010 at 11:29 AM, Vinh Nguyen <vinhdizzo at gmail.com> wrote:
6. ?How do I compile the .cpp file on the command line? ?I got the following based on Dirk's HPC talk but getting errors on my mac os x:
The easiest way by far is to make a package and follow the guidelines of our last release notes. See the section "Using Rcpp in other packages" here http://romainfrancois.blog.free.fr/index.php?post/2010/05/17/Rcpp-0.8.0 The next easy way is to build on the smartness of the inline package. With verbose = TRUE, it will show you how to run the show: fx <- cppfunction( , "return R_NilValue ;", verbose = TRUE )
Can you guys take a look at this and help? First, I have Rcpp and RcppArmadillo installed. Don't know if I have to install Armadillo itself. I compile using: ~> PKG_CXXFLAGS="-I/gnet/home/home8/user24/nguyenv9/Rlib/Rcp p/include -I/gne/home/nguyenv9/Rlib/RcppArmadillo/include" PKG_LIBS="-L/gnet/hom e/home8/user24/nguyenv9/Rlib/Rcpp/lib -lRcpp -Wl,-rpath,/gnet/home/home8/user24/ nguyenv9/Rlib/Rcpp/lib -L/gne/home/nguyenv9/Rlib/RcppArmadillo/lib -Wl,-rpath,/g ne/home/nguyenv9/Rlib/RcppArmadillo/lib" R CMD SHLIB PH_CIC_Rcpp.cpp g++ -I/gne/home/nguyenv9/R-2.11.0/include -I/usr/local/include -I/gnet/home/h ome8/user24/nguyenv9/Rlib/Rcpp/include -I/gne/home/nguyenv9/Rlib/RcppArmadillo/i nclude -fpic -g -O2 -c PH_CIC_Rcpp.cpp -o PH_CIC_Rcpp.o g++ -shared -L/usr/local/lib64 -o PH_CIC_Rcpp.so PH_CIC_Rcpp.o -L/gnet/home/home 8/user24/nguyenv9/Rlib/Rcpp/lib -lRcpp -Wl,-rpath,/gnet/home/home8/user24/nguyen v9/Rlib/Rcpp/lib -L/gne/home/nguyenv9/Rlib/RcppArmadillo/lib -Wl,-rpath,/gne/hom e/nguyenv9/Rlib/RcppArmadillo/lib everything is OK In R:
dyn.load("PH_CIC_Rcpp.so")
Error in dyn.load("PH_CIC_Rcpp.so") :
unable to load shared library '/gnet/home/home8/user24/nguyenv9/PH_CIC_Rcpp.so
':
/gnet/home/home8/user24/nguyenv9/PH_CIC_Rcpp.so: undefined symbol: dgetri_
NOTE: This error didn't begin to occur until I started doing matrix
inversion, additon, etc, usign the armadillo classes.
Also, I didn't include BLAS or LAPACK linking -- still don't know how
to get the compilation flags easily. I read the skeleton stuff but I
don't understand (sorry).
Thanks.
Vinh
On 2010-05-26, at 4:08 PM, Vinh Nguyen wrote:
Also, I didn't include BLAS or LAPACK linking -- still don't know how to get the compilation flags easily. I read the skeleton stuff but I don't understand (sorry).
Just put in your package's 'src' directory the Makevars file that's generated by RcppArmadillo's package.skeleton function. This is what it looks like on my machine: PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) How do you compile the code, by the way? It sounds like you do it by hand. Why not let R do it? With the above Makevars and the correct 'Depends' line in your package description (again, see the skeleton), you won't have to muck about with compiler switches and lookup paths, and everything should 'just work'. Davor
On Wed, May 26, 2010 at 6:31 PM, Davor Cubranic <cubranic at stat.ubc.ca> wrote:
On 2010-05-26, at 4:08 PM, Vinh Nguyen wrote:
Also, I didn't include BLAS or LAPACK linking -- still don't know how to get the compilation flags easily. ? I read the skeleton stuff but I don't understand (sorry).
Just put in your package's 'src' directory the Makevars file that's generated by RcppArmadillo's package.skeleton function. This is what it looks like on my machine: PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) How do you compile the code, by the way? It sounds like you do it by hand. Why not let R do it? With the above Makevars and the correct 'Depends' line in your package description (again, see the skeleton), you won't have to muck about with compiler switches and lookup paths, and everything should 'just work'. Davor
Yes, I'm doing it by hand since I'm still coding. I compile after some progress to make sure everything is OK. Let's say I place the my code in in /src. Do I HAVE to turn this into a package in order to compile? Or is there a way to compile from here. Sorry I'm new at this approach. Thanks. Vinh
Le 27/05/10 05:07, Vinh Nguyen a ?crit :
On Wed, May 26, 2010 at 6:31 PM, Davor Cubranic<cubranic at stat.ubc.ca> wrote:
On 2010-05-26, at 4:08 PM, Vinh Nguyen wrote:
Also, I didn't include BLAS or LAPACK linking -- still don't know how to get the compilation flags easily. I read the skeleton stuff but I don't understand (sorry).
Just put in your package's 'src' directory the Makevars file that's generated by RcppArmadillo's package.skeleton function. This is what it looks like on my machine: PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" ) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) How do you compile the code, by the way? It sounds like you do it by hand. Why not let R do it? With the above Makevars and the correct 'Depends' line in your package description (again, see the skeleton), you won't have to muck about with compiler switches and lookup paths, and everything should 'just work'. Davor
Yes, I'm doing it by hand since I'm still coding. I compile after some progress to make sure everything is OK.
It is not much longer to compile a package is it ?
Let's say I place the my code in in /src. Do I HAVE to turn this into a package in order to compile? Or is there a way to compile from here. Sorry I'm new at this approach.
You don't have to, but it makes your life easier. Now that we use
LinkingTo: Rcpp, RcppArmadillo it makes our Makevars smaller and more
robust. R figures out on its own where to find Rcpp and RcppArmadillo
include paths.
If you don't want to use what R and Rcpp provides for you, you can
emulate this by using this Makevars :
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" )
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()" )
$(shell Rscript -e "cat( '-I', system.file('include', package =
'RcppArmadillo'), sep = '' )" )
The PKG_LIBS line is the same that the one that gets generated by
RcppArmadillo.package.skeleton.
The PKG_CXXFLAGS line pulls in the include path of Rcpp and RcppArmadillo.
Just save this as a "Makevars" in the directory where your cpp files
are, and run:
R CMD SHLIB *cpp -o mylib.so
I will add a RcppArmadillo:::CxxFlags() for consistency between Rcpp and
RcppArmadillo.
Romain
Thanks. Vinh
Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/cork4b : highlight 0.1-8 |- http://bit.ly/bklUXt : RcppArmadillo 0.2.1 `- http://bit.ly/936ck2 : Rcpp 0.8.0
On Wed, May 26, 2010 at 11:33 PM, Romain Francois
<romain at r-enthusiasts.com> wrote:
You don't have to, but it makes your life easier. Now that we use LinkingTo:
Rcpp, RcppArmadillo it makes our Makevars smaller and more robust. R figures
out on its own where to find Rcpp and RcppArmadillo include paths.
If you don't want to use what R and Rcpp provides for you, you can emulate
this by using this Makevars :
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" )
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()" )
$(shell Rscript -e "cat( '-I', system.file('include', package =
'RcppArmadillo'), sep = '' )" )
The PKG_LIBS line is the same that the one that gets generated ?by
RcppArmadillo.package.skeleton.
The PKG_CXXFLAGS line pulls in the include path of Rcpp and RcppArmadillo.
Just save this as a "Makevars" in the directory where your cpp files are,
and run:
R CMD SHLIB *cpp -o mylib.so
I will add a RcppArmadillo:::CxxFlags() for consistency between Rcpp and
RcppArmadillo.
Romain
Thanks Romain. This is what I'm used to while working with compiled code for R.
On 27 May 2010 at 08:05, Vinh Nguyen wrote:
| On Wed, May 26, 2010 at 11:33 PM, Romain Francois
| <romain at r-enthusiasts.com> wrote:
| > If you don't want to use what R and Rcpp provides for you, you can emulate
| > this by using this Makevars :
| >
| > PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" )
| > $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
| > PKG_CXXFLAGS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()" )
| > $(shell Rscript -e "cat( '-I', system.file('include', package =
| > 'RcppArmadillo'), sep = '' )" )
| >
| >
| > The PKG_LIBS line is the same that the one that gets generated ?by
| > RcppArmadillo.package.skeleton.
| >
| > The PKG_CXXFLAGS line pulls in the include path of Rcpp and RcppArmadillo.
| >
| > Just save this as a "Makevars" in the directory where your cpp files are,
| > and run:
| >
| > R CMD SHLIB *cpp -o mylib.so
| >
| >
| > I will add a RcppArmadillo:::CxxFlags() for consistency between Rcpp and
| > RcppArmadillo.
| >
| > Romain
|
| Thanks Romain. This is what I'm used to while working with compiled code for R.
Two cautious words of advice: Don't.
I did that too (which is how you copied it from the HPC Tutorial notes) but
using things like inline is just so much easier. Now, it's a little tricky
with RcppArmadillo and the ordering of the header files but that's why we
gave you the corresponding RcppArmadillo.package.skeleton()
Regards, Dirk
My next question is: if I have both .c and .cpp files in ./src/ is made from RcppArmadillo's skeleton function is OK right? I never understood the stuff about libraries and headers so I never know what's going on under the hood. I just tried building a package with both kinds of files and the package built without an error. Thanks. Vinh
On Thu, May 27, 2010 at 8:05 AM, Vinh Nguyen <vinhdizzo at gmail.com> wrote:
On Wed, May 26, 2010 at 11:33 PM, Romain Francois <romain at r-enthusiasts.com> wrote:
You don't have to, but it makes your life easier. Now that we use LinkingTo:
Rcpp, RcppArmadillo it makes our Makevars smaller and more robust. R figures
out on its own where to find Rcpp and RcppArmadillo include paths.
If you don't want to use what R and Rcpp provides for you, you can emulate
this by using this Makevars :
PKG_LIBS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()" )
$(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
PKG_CXXFLAGS = $(shell $(R_HOME)/bin/Rscript -e "Rcpp:::CxxFlags()" )
$(shell Rscript -e "cat( '-I', system.file('include', package =
'RcppArmadillo'), sep = '' )" )
The PKG_LIBS line is the same that the one that gets generated ?by
RcppArmadillo.package.skeleton.
The PKG_CXXFLAGS line pulls in the include path of Rcpp and RcppArmadillo.
Just save this as a "Makevars" in the directory where your cpp files are,
and run:
R CMD SHLIB *cpp -o mylib.so
I will add a RcppArmadillo:::CxxFlags() for consistency between Rcpp and
RcppArmadillo.
Romain
Thanks Romain. ?This is what I'm used to while working with compiled code for R.
On 27 May 2010 at 08:19, Vinh Nguyen wrote:
| My next question is: if I have both .c and .cpp files in ./src/ is
| made from RcppArmadillo's skeleton function is OK right? I never
| understood the stuff about libraries and headers so I never know
| what's going on under the hood. I just tried building a package with
| both kinds of files and the package built without an error.
These are basic questions that are addressed by, inter alia,
- the R Extensions manual
- examples among the 2300+ packages on CRAN
- books such as V + R's "S Programming", Gentleman's "R Programming for
BioInformatics" (which is not about BioInformatics) or Chambers
"Software for Data Analysis"
But it is off-topic here.
You need to teach yourself the mechanics of doing a package with one function
calling one C or C++ function.
Once you grok that, try one that calls an external library. Once you grok
both those aspects come back to RcppArmadillo.
You are fighting too many moving parts at once.
Regards, Dirk