Michael Hannon | 22 May 09:29
Picon
Favicon
Gravatar

Problem with RInside "hello world" example

Greetings.  I'm trying to go through some of the examples in the notes from
Dirk's Rcpp Masterclass of 28 April 2011.  (I didn't take the class.  I just
found the notes on the Internet.  Please let me know if my use of them
violates some law or protocol.  In case it makes any difference, I'm not
making any money from this project.)

I've run into a problem with the RInside "hello world" example.  I can not
get it to compile on my system.  The first of the many error messages is:

    undefined reference to `RInside::RInside(int, char const* const*, bool)

I've appended the details.  I get the same error if I omit the reference to
the c++0x standard.  What am I missing?

Thanks,

-- Mike

$ g++ --version
g++ (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2)
Copyright (C) 2011 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.

$ cat RI-hw.cpp 

#include <RInside.h>              // embedded R via RInside

int main(int argc, char *argv[]) {

(Continue reading)

Dirk Eddelbuettel | 21 May 19:28
Picon
Favicon
Gravatar

ANN: RcppArmadillo 0.3.2.0


Conrad released a new stable version 3.2.0 of Armadillo which I wrapped into
RcppArmadillo 0.3.2.0. This version is now on CRAN.  

RcppArmadillo pre-releases do appear on R-Forge, and I did test the most
recent pre-release on a number of CRAN packages depending on RcppArmadillo to
ensure that everything still builds as usual.

The NEWS entries since 0.3.0.3 are below, summarizing the changes for the new
major release:

0.3.2.0  2012-05-21

    o   Upgraded to Armadillo release 3.2.0 "Creamfields"

    	  * faster eigen decomposition via "divide and conquer" algorithm
    	  * faster transpose of vectors and compound expressions
    	  * faster handling of diagonal views
    	  * faster handling of tiny fixed size vectors (≤ 4 elements)
    	  * added unique(), for finding unique elements of a matrix

0.3.1.94  2012-05-15

    o   Upgraded to Armadillo release 3.1.94 "v3.2 beta 2"

    	  * added unique(), for finding unique elements of a matrix
    	  * faster eigen decomposition via "divide and conquer" algorithm
    	  * faster transpose of vectors and compound expressions
    	  * faster handling of tiny fixed size vectors (≤ 4 elements)

(Continue reading)

Douglas Bates | 16 May 21:31
Picon
Favicon

Memory problem when compiling Rcpp/RcppEigen/lme4 with clang++

I have been running into yet another memory problem in testing the
development version of lme4.  After doing the usual valgrind,
gctorture, gdb, etc. dance I found that the problem was originating in
the destructor of an Eigen object that included some cholmod
structures.  The problem was that the particular place where it was
failing is not a place where it should have gotten to.  (It should
only have called cholmod_free_factor and it was failing in
cholmod_free_dense.  Both of these are routines that are exposed
through the funky R_GetCCallable function in
RcppEigen/inst/include/RcppEigenStubs.h).  The problem went away when
I switched to g++.  For the time being I would recommend caution if
you choose to use clang++ to compile code linking to RcppEigen.
Alexey Stukalov | 12 May 19:03
Picon

Rostream.h header

Dear Rcpp developers,

ATM to define the Rcpp::Rostream I have to fix the iostream/Rostream.h header directly and add

#include "Rstreambuf.h"

before its declarations.

Including "Rstreambuf.h" in my source file before "Rstreambuf.h" doesn't help,
it seems the headers are processed in a way that Rostream declaration comes before Rstreambuf
(due to RcppCommon.h that is included by Rstreambuf.h and not by Rostream.h).

Is it possible to fix Rostream.h in the mainline or there's another proper way to include it?

Thank you,
   Alexey
_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@...
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Nelson Villoria | 11 May 15:06
Picon
Favicon

translate an R vectorized loop with three logical conditions to C++

I am new to this list, so I hope this is the right place to ask this 
question. I am trying to translate the R vectorized loop below to C++ in 
order to speed up my calculations:

Let:
 > n1
  [1] 1 1 2 2 2 3 3 4 4 4 5 5 5 5 6 6 6 7 7 8 8 8 9 9
 > n2
  [1] 2 4 1 3 5 2 6 1 5 7 2 4 6 8 3 5 9 4 8 5 7 9 6 8
 > w1w1
  [1] 0.2500000 0.2500000 0.1111111 0.1111111 0.1111111 0.2500000 0.2500000
  [8] 0.1111111 0.1111111 0.1111111 0.0625000 0.0625000 0.0625000 0.0625000
[15] 0.1111111 0.1111111 0.1111111 0.2500000 0.2500000 0.1111111 0.1111111
[22] 0.1111111 0.2500000 0.2500000

My vectorized loop is:

     tWSWS.k <- lapply(c(1:length(n1)), function(.n1){
       lapply(c(1:length(n2)), function(.n2){
         if(.n1!=.n2){
          w1w1[n1==.n1 & n2==.n2]
        }})})

result=sum(unlist(tWSWS.k))

Could you help me with this translation or at least point me out to some 
reference/example?

Thanks!

Nelson

--

-- 
Nelson Villoria
Research Assistant Professor
Center for Global Trade Analysis
Department of Agricultural Economics
Purdue University
403 W. State St
West Lafayette IN 47906
765.494.4303
nvillori@...
Dirk Eddelbuettel | 10 May 15:45
Picon
Favicon
Gravatar

RcppArmadillo 0.3.1.92 on R-Forge


Conrad never rests, and has a first Armadillo test release 3.1.92 out en
route to a new Armadillo version 3.2.0.

I have wrapped this into RcppArmadillo 0.3.1.92. As the CRAN maintainers are
trying to throttle uploads down a little, I will not push it to CRAN.  

But for those who are interested in trying the newest version, you should get
it (once R-Forge builds tarballs from it, say tomorrow) via

  install.packages("RcppArmadillo", repos="http://R-Forge.R-project.org")

and you can of course also always do an 'svn up' to fetch it.

Cheers, Dirk

--

-- 
R/Finance 2012 Conference on May 11 and 12, 2012 at UIC in Chicago, IL
See agenda, registration details and more at http://www.RinFinance.com
Jiqiang Guo | 9 May 05:17
Picon

type information about elements in Rcpp::List

Hi,


Thank Dirk first for replying to my previous questions so fast. 

Another question:

Suppose I have a function in CPP as 

void cppfun(Rcpp::List lst) {
    ......
}

Then I would like to call this cppfun in R code as say 
cppfun(list(a=a, b=b, c=c, ...)), in which 
a, b, c could be of different types and their type might be different as this 
function gets called another time.  So I would like to know the type of a, b, c 
in the CPP code.  Could someone help me out or point to me some other 
approaches?  Thanks.

Best,
Jiqiang 

_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@...
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
James Simone | 9 May 00:51
Favicon

help packaging Rcpp modules

I have followed the Rcpp developer's recommendation that a package
greatly simplifies using RCPP_MODULE wrappering. Unfortunately, I'm
having difficulty building and checking even a simple package
containing an Rcpp module. I have read previous posts on this topic
but I did not find anything helpful. I must be overlooking something
very simple, please help.

The package check fails with this error:
** testing if installed package can be loaded
Error : .onLoad failed in loadNamespace() for 'mod', details:
   call: value[[3L]](cond)
   error: failed to load module mod from package mod
no binding for "norm"

The package skeleton was created with Rcpp.package.skeleton() to which
I added a C++ source file and then edited files according to the
'Read-and-delete-me' file.

Here are my build and check steps:

$ R CMD build mod
* checking for file `mod/DESCRIPTION' ... OK
* preparing `mod':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* checking for LF line-endings in source and make files
* checking for empty or unneeded directories
* building `mod_1.0.tar.gz'

$ R CMD check mod
* using log directory '/home/simone/R/Rcpp/module/mod.Rcheck'
* using R version 2.13.1 (2011-07-08)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
* checking for file 'mod/DESCRIPTION' ... OK
* checking extension type ... Package
* this is package 'mod' version '1.0'
* checking package name space information ... OK
* checking package dependencies ... OK
* checking if this is a source package ... OK
* checking for executable files ... OK
* checking whether package 'mod' can be installed ... ERROR
Installation failed.

The package skeleton was created with Rcpp.package.skeleton().

Here is the module directory structure:
$ /bin/ls -R mod
mod:
DESCRIPTION  man  NAMESPACE  R  Read-and-delete-me  src

mod/man:
mod-package.Rd

mod/R:
zzz.R

mod/src:
Makevars  Makevars.win  rcpp_module.cpp

Here are the key files:

$ cat mod/NAMESPACE
useDynLib(mod)
exportPattern("^[[:alpha:]]+")
import( Rcpp )

$ cat mod/R/zzz.R

.onLoad <- function(libname, pkgname) {
     require("methods", character=TRUE, quietly=FALSE)
     loadRcppModules()
}

$ cat mod/src/rcpp_module.cpp
#include <math.h>
#include <Rcpp.h>

double norm( double x, double y ) {
   return sqrt( x*x + y*y );
}

RCPP_MODULE(mod) {
   using namespace Rcpp;
   function( "norm", &norm );
}
Jelmer Ypma | 8 May 17:45
Picon

Compilation error using Rcpp::as<Eigen::MatrixXd>

Hi all,

I've been happily using the RcppEigen package for a couple of
projects, but now I'm running into problems converting a matrix from R
into an Eigen::MatrixXd. Converting an R matrix to an
Eigen::Map<Eigen::MatrixXd> works fine, but I would like to (deep)copy
the values from R to a C++ Eigen::MatrixXd object. From the definition
for the Exporter for Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>
in RcppEigen/inst/include/RcppEigenWrap.h, it looks like
Rcpp::as<Eigen::MatrixXd> could be used, but when compiling some
example code (see below) I get an error (see below). Compiling the
same code with an arma::mat or with Eigen::Map<Eigen::MatrixXd> does
not result in any errors.

Does anyone have an idea what is causing this?

Many thanks in advance and best wishes,
Jelmer

> sessionInfo()
R version 2.15.0 (2012-03-30)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United
Kingdom.1252    LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] inline_0.3.8          RcppArmadillo_0.3.0.3 RcppEigen_0.2.0
Rcpp_0.9.10

loaded via a namespace (and not attached):
[1] grid_2.15.0    lattice_0.20-6 Matrix_1.0-6   tools_2.15.0

The error I get, is:

In file included from c:/tools/R/library/RcppEigen/include/Eigen/Core:282:0,
                 from c:/tools/R/library/RcppEigen/include/Eigen/Dense:1,
                 from
c:/tools/R/library/RcppEigen/include/RcppEigenForward.h:29,
                 from c:/tools/R/library/RcppEigen/include/RcppEigen.h:25,
                 from file160c52054c0.cpp:3:
c:/tools/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:
In member function 'Eigen::DenseCoeffsBase<Derived, 1>::Scalar&
Eigen::DenseCoeffsBase<Derived,
1>::operator[](Eigen::DenseCoeffsBase<Derived, 1>::Index) [with
Derived = Eigen::Matrix<double, -0x00000000000000001,
-0x00000000000000001>, Eigen::DenseCoeffsBase<Derived, 1>::Scalar =
double, Eigen::DenseCoeffsBase<Derived, 1>::Index = int]':
c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:89:3:
instantiated from 'void Rcpp::internal::export_indexing__impl(SEXP,
T&, Rcpp::traits::false_type) [with T = Eigen::Matrix<double,
-0x00000000000000001, -0x00000000000000001>, value_type = double, SEXP
= SEXPREC*, Rcpp::traits::false_type =
Rcpp::traits::integral_constant<bool, false>]'
c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:109:6:
instantiated from 'void
Rcpp::internal::export_indexing__dispatch(SEXP, T&,
Rcpp::traits::r_type_primitive_tag) [with T = Eigen::Matrix<double,
-0x00000000000000001, -0x00000000000000001>, value_type = double, SEXP
= SEXPREC*]'
c:/tools/R/library/Rcpp/include/Rcpp/internal/export.h:127:6:
instantiated from 'void Rcpp::internal::export_indexing(SEXP, T&)
[with T = Eigen::Matrix<double, -0x00000000000000001,
-0x00000000000000001>, value_type = double, SEXP = SEXPREC*]'
c:/tools/R/library/Rcpp/include/Rcpp/traits/Exporter.h:86:17:
instantiated from 'T Rcpp::traits::MatrixExporter<T,
value_type>::get() [with T = Eigen::Matrix<double,
-0x00000000000000001, -0x00000000000000001>, value_type = double]'
c:/tools/R/library/Rcpp/include/Rcpp/as.h:53:33:   instantiated from
'T Rcpp::internal::as(SEXP, Rcpp::traits::r_type_generic_tag) [with T
= Eigen::Matrix<double, -0x00000000000000001, -0x00000000000000001>,
SEXP = SEXPREC*]'
c:/tools/R/library/Rcpp/include/Rcpp/as.h:75:89:   instantiated from
'T Rcpp::as(SEXP) [with T = Eigen::Matrix<double,
-0x00000000000000001, -0x00000000000000001>, SEXP = SEXPREC*]'
file160c52054c0.cpp:31:40:   instantiated from here
c:/tools/R/library/RcppEigen/include/Eigen/src/Core/DenseCoeffsBase.h:388:7:
error: 'THE_BRACKET_OPERATOR_IS_ONLY_FOR_VECTORS__USE_THE_PARENTHESIS_OPERATOR_INSTEAD'
is not a member of 'Eigen::internal::static_assertion<false>'
make: *** [file160c52054c0.o] Error 1

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

The code I used for the example is:

library('RcppEigen')
library('RcppArmadillo')
library('inline')

# Define C++ some function that uses a matrix as input.
# MatrixType will be defined using a typedef in includes,
# when compiling the function below.
# MatrixType will take on values
#   * arma::mat
#   * Eigen::MatrixXd
#   * Eigen::Map<Eigen::MatrixXd>
printMatrix_code <- '
MatrixType _A( Rcpp::as<MatrixType>( A ) );

Rcpp::Rcout << "_A: " << std::endl << _A << std::endl;

return R_NilValue;
'

# Define some matrix A
set.seed( 3141 )
A <- matrix( rnorm( 10 ), nrow=5, ncol=2 )
A

# Compile using MatrixType = arma::mat
# (WORKS)
try( {
printArmaMatrix <- cxxfunction(
    signature(A="matrix"),
    printMatrix_code,
    plugin="RcppArmadillo",
    includes = 'typedef arma::mat MatrixType;',
    verbose=TRUE )

printArmaMatrix( A )
} )

# Compile using MatrixType = Eigen::MatrixXd
# (FAILS)
try( {
printEigenMatrix <- cxxfunction(
    signature(A="matrix"),
    printMatrix_code,
    plugin="RcppEigen",
    includes = 'typedef Eigen::MatrixXd MatrixType;',
    verbose=TRUE )

printEigenMatrix( A )
} )

# Compile using MatrixType = Eigen::Map<Eigen::MatrixXd>
# (WORKS)
try( {
printEigenMappedMatrix <- cxxfunction(
    signature(A="matrix"),
    printMatrix_code,
    plugin="RcppEigen",
    includes = 'typedef Eigen::Map<Eigen::MatrixXd> MatrixType;',
    verbose=TRUE )

printEigenMappedMatrix( A )
} )
Søren Højsgaard | 8 May 01:25
Picon
Picon

Compiling Rcpp on windows platforms

Dear list,

I've noticed a small thing when compiling a .cpp file on windows. Following the Rcpp FAQ document I do

C:\Documents\teaching\2012-ASC\presentations\callingC>Rscript -e "Rcpp:::SHLIB('matprod5.cpp')"
------------------------------------
  Sørens .Rprofile in c:/Documents
------------------------------------
Working directory is:  C:/Documents/teaching/2012-ASC/presentations/callingC
Calling .First() in .Rprofile
exiting .First()
g++ -m64 -shared -s -static-libgcc -o matprod5.dll tmp.def matprod5.o
------------------------------------ S▒rens .Rprofile in c:/Documents -------------------------
----------- Working directory is: C:/Documents/teaching/2012-ASC/presentations/callingC Calling
.First() in .Rprofile exiting .First() C:/programs/R/current/library/
Rcpp/lib/x64/libRcpp.aCalling .Last() in .Rprofile
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/programs/R/curren
t/bin/x64 -lR
g++.exe: error: S?rens: Invalid argument
g++.exe: error: .Rprofile: No such file or directory
g++.exe: error: in: No such file or directory
... bla bla bla ...

This is due to a .First() function etc. in my .Rprofile. I then try to use --vanilla with a similar result

C:\Documents\teaching\2012-ASC\presentations\callingC>Rscript --vanilla -e "Rcpp:::SHLIB('matprod5.cpp')"
g++ -m64 -shared -s -static-libgcc -o matprod5.dll tmp.def matprod5.o
------------------------------------ S▒rens .Rprofile in c:/Documents -------------------------
----------- Working directory is: C:/Documents/teaching/2012-ASC/presentations/callingC Calling
.First() in .Rprofile exiting .First() C:/programs/R/current/library/
Rcpp/lib/x64/libRcpp.aCalling .Last() in .Rprofile
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
-Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/programs/R/curren
t/bin/x64 -lR
g++.exe: error: S?rens: Invalid argument
g++.exe: error: .Rprofile: No such file or directory
g++.exe: error: in: No such file or directory
....

I would have thought that the --vanilla option would make things work. Am I overlooking something or is that
a bug??
(If I remove the .First() function etc. from my .Rprofile then everything works fine. )

The other option mentioned in the FAQ is to do:
R --vanilla CMD SHLIB matprod5.cpp

- and that works fine (it doesn't if I omit --vanilla). This works because I have created a Makevars file with
the lines:

PKG_LIBS=`Rscript -e "Rcpp:::LdFlags()"`
PKG_CXXFLAGS=`Rscript -e "Rcpp:::CxxFlags()"`

According to the FAQ, each line should start with 'export' but that is a *nix command, not a windows command.
Perhaps it would be worthwhile mentioning this in the faq.

Best regards
Søren


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel <at> lists.r-forge.r-project.org
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Jiqiang Guo | 8 May 00:23
Picon

examples on Extending Rcpp::as

Hi,

we know that we could extend as.  I would like to create an user-defined class 
instance from an SEXP (say a list in R).  Where could I find more examples on 
this usage?  

Thanks,
Jiqiang 


_______________________________________________
Rcpp-devel mailing list
Rcpp-devel@...
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel

Gmane