Commit 8f1d2700 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 0.2.13

parents
This diff is collapsed.
Package: RInside
Title: C++ Classes to Embed R in C++ Applications
Version: 0.2.13
Date: 2015-05-20
Author: Dirk Eddelbuettel and Romain Francois
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Description: C++ classes to embed R in C++ applications
The 'RInside' packages makes it easier to have "R inside" your C++ application
by providing a C++ wrapper class providing the R interpreter.
.
As R itself is embedded into your application, a shared library build of R
is required. This works on Linux, OS X and even on Windows provided you use
the same tools used to build R itself.
.
Numerous examples are provided in the eight subdirectories of the examples/
directory of the installed package: standard, mpi (for parallel computing)
qt (showing how to embed 'RInside' inside a Qt GUI application), wt (showing
how to build a "web-application" using the Wt toolkit), armadillo (for
'RInside' use with 'RcppArmadillo') and eigen (for 'RInside' use with 'RcppEigen').
The example use GNUmakefile(s) with GNU extensions, so a GNU make is required
(and will use the GNUmakefile automatically).
.
Doxygen-generated documentation of the C++ classes is available at the
'RInside' website as well.
Depends: R (>= 2.10.0)
Imports: Rcpp (>= 0.11.0)
LinkingTo: Rcpp
URL: http://dirk.eddelbuettel.com/code/rinside.html
License: GPL (>= 2)
BugReports: https://github.com/eddelbuettel/rinside/issues
MailingList: Please send questions and comments regarding RInside to
rcpp-devel@lists.r-forge.r-project.org
NeedsCompilation: yes
Packaged: 2015-05-20 12:59:06.680335 UTC; edd
Repository: CRAN
Date/Publication: 2015-05-20 15:19:30
41f69cadb1e439eea15dd55dd8806b75 *ChangeLog
791eb9c16e21ed69004591e710142b19 *DESCRIPTION
721b51fcc45ba3c8ff2290bc8f55f890 *NAMESPACE
6cc655a76514542527d297ddf6d64e31 *R/RInsidePaths.R
221b942b14cc416f187593b9a662d970 *R/zzz.R
fb3f2916fcfccd5fcef22ee87d8d83dd *README.md
3957781126f406fe956fc87441173ce0 *cleanup
a354953bc638adfe8fb1143a2428eb67 *cleanup.win
6dfc48dbae965bfa0252f4739b6362ae *inst/NEWS.Rd
6721423fd66ead7a6fd303e6ec8b4d49 *inst/THANKS
f80b0a9850ed5c911c690ec9f6520570 *inst/examples/armadillo/GNUmakefile
355f2e6af82135dac79496afd1ae57bc *inst/examples/armadillo/cmake/CMakeLists.txt
bd5497b7c0899be80715c7a2e53042e7 *inst/examples/armadillo/cmake/WIN.readme.txt
a85814fb53b3bbfb2fe7af0d15da33a1 *inst/examples/armadillo/rinside_arma0.cpp
80cfd5e8f32ecc65a49a99664e445522 *inst/examples/armadillo/rinside_arma1.cpp
04d75af950f45921fe54bbc6bdce3fff *inst/examples/eigen/GNUmakefile
f7bcd4fdad18fac76e2584c4df6b3476 *inst/examples/eigen/cmake/CMakeLists.txt
bd5497b7c0899be80715c7a2e53042e7 *inst/examples/eigen/cmake/WIN.readme.txt
6142a963def1a600cb89f036e7ed75e8 *inst/examples/eigen/rinside_eigen0.cpp
8d317f529403b100ea99fc208ed2efc5 *inst/examples/eigen/rinside_eigen1.cpp
9572105fa192851b7b5a2dfbb43f0e38 *inst/examples/mpi/GNUmakefile
543e0e1d7bd34c9408b5429ef850674f *inst/examples/mpi/cmake/CMakeLists.txt
6f2194e3e964422db524c24e3023206e *inst/examples/mpi/rinside_mpi_sample0.cpp
4ad324adeb8ff397d94587d3f911aafd *inst/examples/mpi/rinside_mpi_sample1.cpp
5ff649ec1e283dedd3d78991552fd4a1 *inst/examples/mpi/rinside_mpi_sample2.cpp
f455f4fb464ada55e407db7fbac4d94f *inst/examples/mpi/rinside_mpi_sample3.cpp
98a5f3fb395b5c4789950fd44c018037 *inst/examples/mpi/rinside_mpi_sample4.cpp
48368301a02a909fbe41e8909e4ef465 *inst/examples/qt/README
605fbc24a171e4a168c2e47dd6f1520e *inst/examples/qt/cmake/CMakeLists.txt
6f76c08d0b895f250b52d19cf85630ed *inst/examples/qt/main.cpp
ae117c46fb726e9c51dff253a103565e *inst/examples/qt/qtdensity.cpp
5f7fbd7ce902c4b23d73d3816df1dd8b *inst/examples/qt/qtdensity.h
49f086d0d9a4521bda8b9f28c2c4e01b *inst/examples/qt/qtdensity.pro
72b08213ee496cf2ad16b03660e3df62 *inst/examples/sandboxed_server/GNUmakefile
ee76b78f4ba19a94cf7444410bdf867f *inst/examples/sandboxed_server/client/callback_helper.h
84b60f1aa78679f87ca2a6a877b8306b *inst/examples/sandboxed_server/client/rinsideclient.cpp
268ab56a244f946604aa05c3b5c45ae9 *inst/examples/sandboxed_server/client/rinsideclient.h
0934459516cd0a9a0e3f483b050d2558 *inst/examples/sandboxed_server/common/binarystream.cpp
85aa98dc9d117afda48136f94124d844 *inst/examples/sandboxed_server/common/binarystream.h
346d6fbd0b1cee04dc7c1614c602b0cc *inst/examples/sandboxed_server/common/constants.h
73c52a33e93431ac45604ccc1d91cd8e *inst/examples/sandboxed_server/common/typeid.h
911b55c31ef3d36c45fc49101937b3f4 *inst/examples/sandboxed_server/datatypes/bar.cpp
f80099b82496682ca4804dd9fa5f9610 *inst/examples/sandboxed_server/datatypes/bar.h
5c07e7924ffce8be1cbabe668853e48d *inst/examples/sandboxed_server/datatypes/bar_rcpp_wrapper_declarations.h
3c25043902ee9a9cbbd5ef55a4f667aa *inst/examples/sandboxed_server/datatypes/bar_rcpp_wrapper_definitions.h
330625ad4991a296d1d1fb5acb20212e *inst/examples/sandboxed_server/datatypes/foo.cpp
ab2699f8c40fac20b8aeb3920efb026e *inst/examples/sandboxed_server/datatypes/foo.h
ae9378659614ffc4680a13c99bd92aa8 *inst/examples/sandboxed_server/datatypes/foo_rcpp_wrapper_declarations.h
7f31051c1df73805ddba67055883ae13 *inst/examples/sandboxed_server/datatypes/foo_rcpp_wrapper_definitions.h
59bbecd246a56bf97236a4326cad57ed *inst/examples/sandboxed_server/example_client.cpp
67863fecc8fdc91bbf062c816e7da4be *inst/examples/sandboxed_server/example_server.cpp
5443cb9f600e03b0069243ac456eaf4a *inst/examples/sandboxed_server/server/internalfunction_clone.h
9864204bed904f145d8fb65fb0b452a5 *inst/examples/sandboxed_server/server/rinside_callbacks.h
514aaa118aa669e53b538293bd3ae75c *inst/examples/sandboxed_server/server/rinsideserver.cpp
bece4eb3d2002c32b9687cf34a32819d *inst/examples/sandboxed_server/server/rinsideserver.h
2ea1628c2ce8eda399613f87a8fff0af *inst/examples/standard/GNUmakefile
896df6d28697d491146642d0a82f29bc *inst/examples/standard/Makefile.win
0069cfcbdad4da03a9cf29a45e51f175 *inst/examples/standard/cmake/CMakeLists.txt
7828adbb3a1488e1f70d46bb3dcc7095 *inst/examples/standard/rinside_callbacks0.cpp
5bd98afb4f97c897fb13bb153138e748 *inst/examples/standard/rinside_callbacks1.cpp
284cf376b2cdd3dbf859d3e59e08335d *inst/examples/standard/rinside_module_sample0.cpp
933de0f892c71f54c7159b34fee37827 *inst/examples/standard/rinside_sample0.cpp
2b71c28cbe922ae8b7c20b28ef5acc08 *inst/examples/standard/rinside_sample1.cpp
73fe2510f9e99dc412e1243453012dec *inst/examples/standard/rinside_sample10.cpp
93d40aaff9cf0af2e673b191cf39afcd *inst/examples/standard/rinside_sample11.cpp
f6413f06d156ec79cafa74ecdeb5b42c *inst/examples/standard/rinside_sample12.cpp
5b8b89745e4f1993ac20efd00a1badb2 *inst/examples/standard/rinside_sample13.cpp
c1d320aa52d092e02ddb654c475a7655 *inst/examples/standard/rinside_sample14.cpp
9b2acf2c6aa82e2283055ce761314198 *inst/examples/standard/rinside_sample15.cpp
eee02a8f3f9546b4dd997c09d8d24dc1 *inst/examples/standard/rinside_sample16.cpp
3b658d159e82d4e8cdc3c2002b6f344f *inst/examples/standard/rinside_sample17.cpp
c4c629c2b0fde20be830bd8016f49e24 *inst/examples/standard/rinside_sample2.cpp
3a08885a9066ad1b5d233655ac65604a *inst/examples/standard/rinside_sample3.cpp
00bbc2e162652c972c3d4bec02f398f2 *inst/examples/standard/rinside_sample4.cpp
b4ac171130a6dab397aa4a34f5c46524 *inst/examples/standard/rinside_sample5.cpp
8276394037ce104ddf3b780576c01a5f *inst/examples/standard/rinside_sample6.cpp
d563809a8aa51678215fc5d71a7c3e7d *inst/examples/standard/rinside_sample7.cpp
169bdb51448e248cf9b699a3a7774298 *inst/examples/standard/rinside_sample8.cpp
f25739b53eb3d69f4b9844d454cb15e3 *inst/examples/standard/rinside_sample9.cpp
4112d425e41dd37511639f409ca8d203 *inst/examples/standard/rinside_test0.cpp
78cca921b3470109786237e71d46b0e0 *inst/examples/standard/rinside_test1.cpp
d5e3da4daebe74fdf2ce2b4c1d5dcc27 *inst/examples/standard/rinside_test2.cpp
da7afc2eb974e6af3e8811fe2d8187fa *inst/examples/threads/GNUmakefile
ed012740ba04d6aff8029f2da33c5b74 *inst/examples/threads/boostEx.cpp
83d0dc4471d8136db31b4d4ebdee881e *inst/examples/wt/GNUmakefile
e73ccdb6ea625d4d402ce5873c0fda06 *inst/examples/wt/cmake/CMakeLists.txt
f67f11be2e2a9d671cb29e6b11e5ee7a *inst/examples/wt/wtdensity.cpp
a3920c0503bf8a2239de4ec47528b214 *inst/examples/wt/wtdensity.css
f55a104ad5550cb87d2464f793ebc4ed *inst/examples/wt/wtdensity.xml
2daa9e35371c74c52d7b80e7459778bc *inst/examples/wt/wtdensityPlain.cpp
17f884c08374bc6336b8b6abab8b4e65 *inst/include/Callbacks.h
654aa4c207899c8629037c15814ef58f *inst/include/MemBuf.h
b00fc9ddeddb13051d95b6e5de5e2751 *inst/include/RInside.h
e2bf5d17fea0155140de69d86efcaaa3 *inst/include/RInsideCommon.h
193ebd47832d03c444c3f4d516915062 *inst/include/RInsideConfig.h
9bba313d3c86b9a8038d44704366bee2 *man/RInside-package.Rd
1932ad7bf383cf7bc600f0cf03214d1e *src/Makevars
dae114d711c1c6c1b0fc72c58312c483 *src/Makevars.win
c47d49883a572ae1efcc3f075875f8af *src/MemBuf.cpp
fafaf221c06ec2630d26b106bacabc3e *src/RInside.cpp
c76997e46f501a21ce9a12a127452a7d *src/setenv/setenv.c
e0953bcb1cf6e7732945551f24f7b207 *src/tools/RInsideAutoloads.r
0de3cd168362e5020723217c61485b35 *src/tools/RInsideEnvVars.r
595752b43220c0d19c9f2e2d755bb5c8 *src/tools/unix2dos.r
importFrom(Rcpp, evalCpp)
## Use R's internal knowledge of path settings to find the lib/ directory
## plus optinally an arch-specific directory on system building multi-arch
RInsideLdPath <- function() {
if (nzchar(.Platform$r_arch)) { ## eg amd64, ia64, mips
system.file("lib",.Platform$r_arch,package="RInside")
} else {
system.file("lib",package="RInside")
}
}
## Provide linker flags -- i.e. -L/path/to/libRInside -- as well as an
## optional rpath call needed to tell the Linux dynamic linker about the
## location. This is not needed on OS X where we encode this as library
## built time (see src/Makevars) or Windows where we use a static library
## Updated Jan 2010: We now default to static linking but allow the use
## of rpath on Linux if static==FALSE has been chosen
## Note that this is probably being called from LdFlags()
RInsideLdFlags <- function(static=TRUE) {
rinsidedir <- RInsideLdPath()
if (static) { # static is default on Windows and OS X
flags <- paste(rinsidedir, "/libRInside.a", sep="")
if (.Platform$OS.type=="windows") {
flags <- shQuote(flags)
}
} else { # else for dynamic linking
flags <- paste("-L", rinsidedir, " -lRInside", sep="") # baseline setting
if ((.Platform$OS.type == "unix") && # on Linux, we can use rpath to encode path
(length(grep("^linux",R.version$os)))) {
flags <- paste(flags, " -Wl,-rpath,", rinsidedir, sep="")
}
}
invisible(flags)
}
## Provide compiler flags -- i.e. -I/path/to/RInside.h
RInsideCxxFlags <- function() {
path <- system.file( "include", package = "RInside" )
# if (.Platform$OS.type=="windows") {
# path <- shQuote(path)
# }
sprintf('-I%s', path)
}
## Shorter names, and call cat() directly
CxxFlags <- function() {
cat(RInsideCxxFlags())
}
## LdFlags defaults to static linking on the non-Linux platforms Windows and OS X
LdFlags <- function(static=ifelse(length(grep("^linux",R.version$os))==0, TRUE, FALSE)) {
cat(RInsideLdFlags(static=static))
}
# ## Use R's internal knowledge of path settings to find the lib/ directory
# ## plus optinally an arch-specific directory on system building multi-arch
# RInsideLdPath <- function() {
# Rcpp:::packageLibPath( package = "RInside" )
# }
## Provide linker flags -- i.e. -L/path/to/libRInside -- as well as an
## optional rpath call needed to tell the Linux dynamic linker about the
## location. This is not needed on OS X where we encode this as library
## built time (see src/Makevars) or Windows where we use a static library
# RInsideLdFlags <- function(static=Rcpp:::staticLinking()) {
# Rcpp:::packageLdFlags( "RInside", static )
# }
## Provide compiler flags -- i.e. -I/path/to/RInside.h
# RInsideCxxFlags <- function() {
# Rcpp:::includeFlag( package = "RInside" )
# }
## Shorter names, and call cat() directly
# CxxFlags <- function() cat(RInsideCxxFlags())
# LdFlags <- function(static=Rcpp:::staticLinking()) cat(RInsideLdFlags(static))
#.First.lib <- function(lib, pkg) {
# cat("Loaded RInside.\n")
#}
## RInside [![Build Status](https://travis-ci.org/eddelbuettel/rinside.svg)](https://travis-ci.org/eddelbuettel/rinside) [![License](http://img.shields.io/badge/license-GPL%20%28%3E=%202%29-brightgreen.svg?style=flat)](http://www.gnu.org/licenses/gpl-2.0.html) [![Downloads](http://cranlogs.r-pkg.org/badges/RInside?color=brightgreen)](http://cran.rstudio.com/package=RInside)
Easy embedding of R inside C++
### About
The RInside package provides a few classes for seamless embedding of [R](http://www.r-project.org) inside of
C++ applications by relying on [Rcpp](http://www.rcpp.org).
Provided with the package itself are eight subdirectories with examples: from
more than a dozen basic command-line examples (in directory `standard`) to
graphical user-interfaces (using both [Qt](http://www.qt.io) and
[Wt](http://www.webtoolkit.eu/wt)), linear algebra with
[Armadillo](http://arma.sf.net) and
[Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page), parallel
computing with MPI to a sandboxed server.
### See Also
The [RInside](http://dirk.eddelbuettel.com/code/rinside.html) web page has
some more details.
### Authors
Dirk Eddelbuettel and Romain Francois
### License
GPL (>= 2)
rm -vf src/*.o src/*.so inst/lib/*.h \
src/RInsideEnvVars.h src/RInsideAutoloads.h \
inst/lib/lib*.so inst/lib/lib*.a \
Librinside.a
for d in standard mpi qt wt armadillo eigen threads
do
cd inst/examples/${d}
test -f Makefile && make clean && rm -f *~
cd ../../..
done
rm -vf src/*.o src/*.so inst/lib/*.h \
inst/lib/lib*.so inst/lib/lib*.a
cd inst/examples/standard && make -f Makefile.win clean && cd -
## cd inst/examples/mpi && make clean && cd -
This diff is collapsed.
Miguel Lechón for finding (and fixing!) a memory-management bug
Daniel F Schwarz for a patch to not override pre-set environment variables
Michael Kane for testing on RHEL
Jan de Leeuw for testing on OS X
Jeffrey Horner for finding and fixing an OS X build bug
Simon Urbanek for OS X (and general) build tips
Richard Holbrey for initial help with the the Windows build
Jianping Hua for contributing two MPI-based examples
Murray Stokely for a patch regarding timing of Rcpp autoloads
James Bates for a patch restoring RInside on Windows
John Brzustowski for a correction to the Windows initialization
Peter Aberline for contributing CMake support for all examples
Theodore Lytras for a patch helping to recover from (some) errors
Spencer Behling for a patch getting the Qt example ready for Qt 5.1
Nicholas Pezolano for a new MPI example
Martin Morgan for a new MPI example
Kevin Ushey for debugging a seg.fault issue post Rcpp 0.11.0
## -*- mode: make; tab-width: 8; -*-
##
## Simple Makefile
## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
R_HOME := $(shell R RHOME)
sources := $(wildcard *.cpp)
programs := $(sources:.cpp=)
## include headers and libraries for R
RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
## if you need to set an rpath to R itself, also uncomment
#RRPATH := -Wl,-rpath,$(R_HOME)/lib
## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
## include headers and libraries for RInside embedding classes
RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
## RcppArmadillo headers
RCPPARMAINCL := $(shell echo 'RcppArmadillo:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
## compiler etc settings used in default make rules
CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RCPPARMAINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS := $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
all: $(programs)
@test -x /usr/bin/strip && strip $^
run: $(programs)
@for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done
clean:
rm -vf $(programs)
rm -vrf *.dSYM
runAll:
for p in $(programs); do echo "Running $$p"; ./$$p; done
cmake_minimum_required(VERSION 2.8.4)
set (VERBOSE 1)
set (SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
execute_process(COMMAND R RHOME
OUTPUT_VARIABLE R_HOME)
file(GLOB sources ${SRC_DIR}/*.cpp)
set(NUM_TRUNC_CHARS 2)
set (RPATH "R")
set (RSCRIPT_PATH "Rscript")
if (CMAKE_HOST_WIN32)
execute_process(COMMAND ${RSCRIPT_PATH} -e "cat(.Platform$r_arch)"
OUTPUT_VARIABLE R_ARCH)
execute_process(COMMAND R --arch ${R_ARCH} RHOME
OUTPUT_VARIABLE R_HOME)
string(REPLACE "\\" "/" R_HOME ${R_HOME})
set (RPATH ${R_HOME}/bin/R)
endif()
set (RCPPFLAGS_CMD " ${RPATH} " " CMD " " config " " --cppflags ")
execute_process(COMMAND ${RPATH} CMD config --cppflags
OUTPUT_VARIABLE RCPPFLAGS)
if (CMAKE_HOST_WIN32)
if (${RCPPFLAGS} MATCHES "[-][I]([^ ;])+")
set (RCPPFLAGS ${CMAKE_MATCH_0})
endif()
endif()
string(SUBSTRING ${RCPPFLAGS} ${NUM_TRUNC_CHARS} -1 RCPPFLAGS)
include_directories(${RCPPFLAGS})
execute_process(COMMAND ${RPATH} CMD config --ldflags
OUTPUT_VARIABLE RLDFLAGS)
string(LENGTH ${RLDFLAGS} RLDFLAGS_LEN)
if (${RLDFLAGS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RLDFLAGS_L)
string(STRIP ${RLDFLAGS_L} RLDFLAGS_L )
link_directories(${RLDFLAGS_L} )
endif()
if (${RLDFLAGS} MATCHES "[-][l]([^;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RLDFLAGS_l)
string(STRIP ${RLDFLAGS_l} RLDFLAGS_l )
endif()
execute_process(COMMAND ${RSCRIPT_PATH} -e "Rcpp:::CxxFlags()"
OUTPUT_VARIABLE RCPPINCL)
string(SUBSTRING ${RCPPINCL} ${NUM_TRUNC_CHARS} -1 RCPPINCL)
include_directories(${RCPPINCL})
execute_process(COMMAND ${RSCRIPT_PATH} -e "Rcpp:::LdFlags()"
OUTPUT_VARIABLE RCPPLIBS)
execute_process(COMMAND ${RSCRIPT_PATH} -e "RInside:::CxxFlags()"
OUTPUT_VARIABLE RINSIDEINCL)
string(SUBSTRING ${RINSIDEINCL} ${NUM_TRUNC_CHARS} -1 RINSIDEINCL)
include_directories(${RINSIDEINCL})
message(${RINSIDEINCL})
execute_process(COMMAND ${RSCRIPT_PATH} -e "RInside:::LdFlags()"
OUTPUT_VARIABLE RINSIDELIBS)
execute_process(COMMAND ${RSCRIPT_PATH} -e "RcppArmadillo:::CxxFlags()"
OUTPUT_VARIABLE RCPPARMADILLOINCL)
string(LENGTH ${RCPPARMADILLOINCL} INCLLENGTH)
math(EXPR INCLLENGTH "${INCLLENGTH}-4")
string(SUBSTRING ${RCPPARMADILLOINCL} 3 ${INCLLENGTH} RCPPARMADILLOINCL)
include_directories(${RCPPARMADILLOINCL})
if (CMAKE_HOST_WIN32)
string(LENGTH "libRcpp.a" lenRcppName)
string(LENGTH ${RCPPLIBS} lenRcppFQName)
math(EXPR RLibPathLen ${lenRcppFQName}-${lenRcppName}-1)
string(SUBSTRING ${RCPPLIBS} 0 ${RLibPathLen} RCPPLIBS_L)
link_directories(${RCPPLIBS_L})
math(EXPR RLibPathLen ${RLibPathLen}+1)
string(SUBSTRING ${RCPPLIBS} ${RLibPathLen} -1 RCPPLIBS_l)
#Remove the quotes
string(SUBSTRING ${RINSIDELIBS} 1 -1 RINSIDELIBS)
string(LENGTH ${RINSIDELIBS} lenRInsideFQNameLen)
math(EXPR lenRInsideFQNameLen ${lenRInsideFQNameLen}-1)
string(SUBSTRING ${RINSIDELIBS} 0 ${lenRInsideFQNameLen} RINSIDELIBS)
string(LENGTH "libRInside.a" lenRInsideName)
string(LENGTH ${RINSIDELIBS} lenRInsideFQName)
math(EXPR RLibPathLen ${lenRInsideFQName}-${lenRInsideName}-1)
string(SUBSTRING ${RINSIDELIBS} 0 ${RLibPathLen} RINSIDELIBS_L)
math(EXPR RLibPathLen ${RLibPathLen}+1)
string(SUBSTRING ${RINSIDELIBS} ${RLibPathLen} -1 RINSIDELIBS_l)
link_directories(${RINSIDELIBS_L})
set ( BLAS_LIBS ${CMAKE_CURRENT_SOURCE_DIR}/libblas.lib)
set ( LAPACK_LIBRARY ${CMAKE_CURRENT_SOURCE_DIR}/liblapack.lib)
link_directories(${CMAKE_CURRENT_SOURCE_DIR})
else()
if (${RCPPLIBS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RCPPLIBS_L)
link_directories(${RCPPLIBS_L} )
endif()
if (${RCPPLIBS} MATCHES "[-][l][R]([^;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RCPPLIBS_l)
endif()
if (${RINSIDELIBS} MATCHES "[-][L]([^ ;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RINSIDELIBS_L)
link_directories(${RINSIDELIBS_L})
endif()
if (${RINSIDELIBS} MATCHES "[-][l][R]([^;])+")
string(SUBSTRING ${CMAKE_MATCH_0} ${NUM_TRUNC_CHARS} -1 RINSIDELIBS_l)
endif()
# If the faster 'gold' linker is used, to avoid complaints about undefined symbol
SET(CMAKE_FIND_LIBRARY_SUFFIXES_SAVED ${CMAKE_FIND_LIBRARY_SUFFIXES}) # Backup
LIST(APPEND CMAKE_FIND_LIBRARY_SUFFIXES ".so.3")
FIND_LIBRARY(BLAS_LIBRARY blas)
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAVED}) # Restore
LIST(APPEND EXTRA_LIBRARIES ${BLAS_LIBRARY})
FIND_LIBRARY(LAPACK_LIBRARY lapack)
endif()
execute_process(COMMAND ${RPATH} CMD config CXXFLAGS
OUTPUT_VARIABLE RCXXFLAGS)
execute_process(COMMAND ${RPATH} CMD config BLAS_LIBS
OUTPUT_VARIABLE RBLAS)
execute_process(COMMAND ${RPATH} CMD config LAPACK_LIBS
OUTPUT_VARIABLE RLAPACK)
set(CMAKE_CXX_FLAGS "-W -Wall -pedantic -Wextra ${CMAKE_CXX_FLAGS}")
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG" OR
CMAKE_BUILD_TYPE STREQUAL "RelWithDebugInfo" )
add_definitions("-DDEBUG")
elseif ( CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
add_definitions("-O3")
endif()
message ("cmake_cxx_flags" ${CMAKE_CXX_FLAGS})
foreach (next_SOURCE ${sources})
get_filename_component(source_name ${next_SOURCE} NAME_WE)
add_executable( ${source_name} ${next_SOURCE} )
target_link_libraries(${source_name} ${RLDFLAGS_l})
target_link_libraries(${source_name} ${BLAS_LIBS})
target_link_libraries(${source_name} ${LAPACK_LIBS})
target_link_libraries(${source_name} ${RINSIDELIBS_l})
target_link_libraries(${source_name} ${RCPPLIBS_l})
target_link_libraries(${source_name} ${EXTRA_LIBRARIES})
target_link_libraries(${source_name} ${LAPACK_LIBRARY})
endforeach (next_SOURCE ${sources})
Building these examples on Windows is a bit more difficult than on Linux.
* Put R in the path:
C:\R\R-2.1X.X\bin
C:\R\R-2.1X.X\bin\i386
* Add required environment variables:
R_HOME C:\R\R-2.1X.X
CYGWIN nodosfilewarning
* Then libpack and libblas for Windows needed to be obtained from:
http://icl.cs.utk.edu/lapack-for-windows/lapack/index.html#libraries_mingw
* The CMakeLists.txt files expect the liblapack.lib and libblas.lib files to be in the same directory as themselves for the Windows build. You can edit lines 7 and 8 of the the CMakeLists.txt files if they are not in this location.
* I generally build in a 'build' directly below cmake:
mkdir build
cd build
cmake -G "Unix Makefiles" ../.
make
To run these example there are further DLL dependencies required not installed by RTools:
libgcc_s_dw2-1.dll
libgfortran.dll
libquadmath-0.dll
liblapack.dll
I was able to grab these by installing MinGW from: http://sourceforge.net/projects/mingw/files/MinGW/Base/gcc/Version4/
Use the version that matches the gcc version that is installed by RTools.
Once installed, either add their location to the PATH, or copy them to either the same directory as the example executable, or put them in the windows/system32 folder.
Peter
peter dot aberline at gmail dot com
// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo classes
//
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
#include <RcppArmadillo.h> // for Armadillo as well as Rcpp
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string cmd = "diag(3)"; // create a Matrix in r
arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
std::cout << m << std::endl; // and use Armadillo i/o
exit(0);
}
// -*- c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
//
// Simple example using Armadillo on matrix data generated in R
//
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
#include <RcppArmadillo.h> // for Armadillo as well as Rcpp
#include <RInside.h> // for the embedded R via RInside
int main(int argc, char *argv[]) {
RInside R(argc, argv); // create an embedded R instance
std::string cmd = "set.seed(42); matrix(rnorm(9),3,3)"; // create a random Matrix in r
arma::mat m = Rcpp::as<arma::mat>(R.parseEval(cmd)); // parse, eval + return result
arma::mat n = m.t() * m;
double nacc = arma::accu(n);
double nrnk = arma::rank(n);
m.print("Initial Matrix m"); // initial random matrix
n.print("Product n = m' * m"); // product of m' * m
std::cout << "accu(n) " << nacc << " "
<< "rank(n) " << nrnk << std::endl; // accu() and rank()
exit(0);
}
## -*- mode: make; tab-width: 8; -*-
##
## Simple Makefile
## comment this out if you need a different version of R,
## and set set R_HOME accordingly as an environment variable
R_HOME := $(shell R RHOME)
sources := $(wildcard *.cpp)
programs := $(sources:.cpp=)
## include headers and libraries for R
RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
## if you need to set an rpath to R itself, also uncomment
#RRPATH := -Wl,-rpath,$(R_HOME)/lib
## include headers and libraries for Rcpp interface classes
## note that RCPPLIBS will be empty with Rcpp (>= 0.11.0) and can be omitted
RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
## include headers and libraries for RInside embedding classes
RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS := $(shell echo 'RInside:::LdFlags()' | $(R_HOME)/bin/R --vanilla --slave)
## RcppEigen headers
RCPPEIGENINCL := $(shell echo 'cat(paste("-I", system.file("include", package = "RcppEigen"), sep = ""))' | $(R_HOME)/bin/R --vanilla --slave)
## compiler etc settings used in default make rules
CXX := $(shell $(R_HOME)/bin/R CMD config CXX)
CPPFLAGS := -Wall $(shell $(R_HOME)/bin/R CMD config CPPFLAGS)
CXXFLAGS := $(RCPPFLAGS) $(RCPPINCL) $(RCPPEIGENINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LDLIBS := $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)
all: $(programs)
@test -x /usr/bin/strip && strip $^
run: $(programs)
@for p in $(programs); do echo; echo "Running $$p:"; ./$$p; done
clean:
rm -vf $(programs)
rm -vrf *.dSYM
runAll:
for p in $(programs); do echo "Running $$p"; ./$$p; done
cmake_minimum_required(VERSION 2.8.4)
set (VERBOSE 1)
set (SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
execute_process(COMMAND R RHOME
OUTPUT_VARIABLE R_HOME)
file(GLOB sources ${SRC_DIR}/*.cpp)
set(NUM_TRUNC_CHARS 2)
set (RPATH "R")
set (RSCRIPT_PATH "Rscript")
if (CMAKE_HOST_WIN32)
execute_process(COMMAND ${RSCRIPT_PATH} -e "cat(.Platform$r_arch)"