[Rcpp-devel] Problem with push_back to a list

Michael Hannon jm_hannon at yahoo.com
Tue Oct 25 21:46:14 CEST 2011


Greetings.  I need to return a list of initially-indeterminate length from
C++.  I found the following note from Romain:

    http://article.gmane.org/gmane.comp.lang.r.rcpp/69/match=push%5fback+list

that seemed to solve the problem.

I made what I thought were some minor tweaks to the example (using cxxfunction
instead of cfunction, for instance) and tried to run it on my system.

The example works fine if I leave out the push of the character string:

    myList.push_back(Rcpp::Named ("foo", "bar"));

but fails with an obscure (to me) compilation error when I include it.

I've appended first the R code and after that the log of an R session in which
I tried to run the code.

I might add that I've tried some variations of the problematic line but have
always gotten compile errors.  Here are a couple of examples:

    myList.push_back(Named ("foo", "bar"));
    myList.push_back(Rcpp::Named ("foo", 10));

Thanks for any help you can provide.

-- Mike

########## R code

library(Rcpp)
library(inline)

includes <- '
'

ccode <- '
    Rcpp::List myList(rList);
    myList.push_back(10);
    myList.push_back(Rcpp::Named ("foo", "bar"));
    return myList;
'

lfun <- cxxfunction(signature(rList = "list"),
                    includes = includes,
                    body     = ccode,
                    plugin   = "Rcpp")

rL <- list(x=1:4, y=letters[1:4])
lfun(rL)

########## Log of an R session that exhibits the compilation problem

$ R --vanilla < pushback.R 

R version 2.13.1 (2011-07-08)
Copyright (C) 2011 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-redhat-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(Rcpp)
> library(inline)
> 
> includes <- '
+ '
> 
> ccode <- '
+     Rcpp::List myList(rList);
+     myList.push_back(10);
+     myList.push_back(Rcpp::Named ("foo", "bar"));
+     return myList;
+ '
> 
> lfun <- cxxfunction(signature(rList = "list"),
+                     includes = includes,
+                     body     = ccode,
+                     plugin   = "Rcpp")
In file included from /usr/lib64/R/library/Rcpp/include/RcppCommon.h:313:0,
                 from /usr/lib64/R/library/Rcpp/include/Rcpp.h:27,
                 from file35af62e2.cpp:4:
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h: In function ‘SEXPREC*
Rcpp::internal::wrap_dispatch_unknown_iterable(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’:
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:638:98:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:654:96:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:669:80:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown_importable(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:687:99:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch(const T&,
Rcpp::traits::wrap_type_unknown_tag) [with T = Rcpp::traits::named_object<char
[4]>, SEXP = SEXPREC*]’
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:791:104:   instantiated
from ‘SEXPREC* Rcpp::wrap(const T&) [with T = Rcpp::traits::named_object<char
[4]>, SEXP = SEXPREC*]’
/usr/lib64/R/library/Rcpp/include/Rcpp/vector/converter.h:68:31:
instantiated from ‘static SEXPREC*
Rcpp::internal::generic_element_converter<RTYPE>::get(const T&) [with T =
Rcpp::traits::named_object<char [4]>, int RTYPE = 19, SEXP = SEXPREC*]’
/usr/lib64/R/library/Rcpp/include/Rcpp/vector/Vector.h:440:9:   instantiated
from ‘void Rcpp::Vector<RTYPE>::push_back(const T&) [with T =
Rcpp::traits::named_object<char [4]>, int RTYPE = 19]’
file35af62e2.cpp:34:48:   instantiated from here
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:433:11: error: cannot
convert ‘const Rcpp::traits::named_object<char [4]>’ to ‘SEXP’ in
initialization
make: *** [file35af62e2.o] Error 1

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

Program source:
  1: 
  2: // includes from the plugin
  3: 
  4: #include <Rcpp.h>
  5: 
  6: 
  7: #ifndef BEGIN_RCPP
  8: #define BEGIN_RCPP
  9: #endif
 10: 
 11: #ifndef END_RCPP
 12: #define END_RCPP
 13: #endif
 14: 
 15: using namespace Rcpp;
 16: 
 17: 
 18: // user includes
 19: 
 20: 
 21: 
 22: // declarations
 23: extern "C" {
 24: SEXP file35af62e2( SEXP rList) ;
 25: }
 26: 
 27: // definition
 28: 
 29: SEXP file35af62e2( SEXP rList ){
 30: BEGIN_RCPP
 31: 
 32:     Rcpp::List myList(rList);
 33:     myList.push_back(10);
 34:     myList.push_back(Rcpp::Named ("foo", "bar"));
 35:     return myList;
 36: 
 37: END_RCPP
 38: }
 39: 
 40: 
Error in compileCode(f, code, language = language, verbose = verbose) : 
  Compilation ERROR, function(s)/method(s) not created! In file included from
/usr/lib64/R/library/Rcpp/include/RcppCommon.h:313:0,
                 from /usr/lib64/R/library/Rcpp/include/Rcpp.h:27,
                 from file35af62e2.cpp:4:
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h: In function ‘SEXPREC*
Rcpp::internal::wrap_dispatch_unknown_iterable(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’:
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:638:98:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch_unknown(const T&,
Rcpp::traits::false_type) [with T = Rcpp::traits::named_object<char [4]>, SEXP
= SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constant<bool,
false>]’
/usr/lib64/R/library/Rcpp/include/Rcpp/internal/wrap.h:654:96:   instantiated
from ‘SEXPREC* Rcpp::internal::wrap_dispatch_eigen(const
Calls: cxxfunction -> compileCode
In addition: Warning message:
running command '/usr/lib64/R/bin/R CMD SHLIB file35af62e2.cpp 2>
file35af62e2.cpp.err.txt' had status 1 
Execution halted
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20111025/b64344ed/attachment-0001.htm>


More information about the Rcpp-devel mailing list