[Rcpp-devel] What are RcppExport, BEGIN_RCPP and END_RCPP?
Hello, What are RcppExport, BEGIN_RCPP and END_RCPP? For example: RccpExport SEXP myFunction( SEXP myVar_s) { BEGIN_RCPP END_RCPP } Are they related to extern C { } ? Further, suppose that I am writing a function that uses both Rcpp and direct access to the inside the SEXP objects, do I need to use extern C { } or has Rcpp done it for me? Best Regards, Slava ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Re: [Rcpp-devel] How do instantiate an Rccpp and/or Armadillo object and then set it's underlying SEXP later?
On 26 October 2011 at 00:02, Slava Razbash wrote: | I will illustrate the idea of what I want to do with an example that | just uses an integer. So for example: | | int myNumber; | nyNumber = 5; | | So can I do something with Rcpp and SEXP objects as below. I know that | my code will be wrong but I am trying to convey an idea, so think of | it a pseudocode. | Pseudocode example: | | SEXP myFunction(SEXP myVector_s ) { |Rcpp::NumericVector myVector; |Rcpp::NumericVector myVector::as(myVector_s); | | } I don;t understand what that is trying to convoy. | Further, will the following work with RcppArmadillo? | | SEXP myFunction(SEXP myVector_s ) { |arma::rowvec myVector; |myVector = Rcpp::asarma::rowvec(myVector_s); | | } The second line is correct. The first line (empty ctor) I am unsure about. Why don't you test it? Generally speaking, if the constructor you think you need is not there, and you really think you need it, then you will have to write a new constructor yourself. Alternatively, you can rethink your problem and/or try to figure out how others have done it. Trying stating more clearly what you want to do, why/how you want to do it and what you actually tried plus any applicable errors. Also don't abuse this list as a C++ tutorial site. There are better ones, and we have limited resources we like to focus on Rcpp. Thanks, Dirk -- Outside of a dog, a book is a man's best friend. Inside of a dog, it is too dark to read. -- Groucho Marx ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] Problem with push_back to a list
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_objectchar [4], SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constantbool, 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_objectchar [4], SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constantbool, 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_objectchar [4], SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constantbool, 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_objectchar [4], SEXP = SEXPREC*, Rcpp::traits::false_type = Rcpp::traits::integral_constantbool, 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_objectchar [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_objectchar [4], SEXP = SEXPREC*]’ /usr/lib64/R/library/Rcpp/include/Rcpp/vector/converter.h:68:31: instantiated from ‘static SEXPREC* Rcpp::internal::generic_element_converterRTYPE::get(const T) [with T = Rcpp::traits::named_objectchar [4], int RTYPE = 19, SEXP = SEXPREC*]’ /usr/lib64/R/library/Rcpp/include/Rcpp/vector/Vector.h:440:9: instantiated from ‘void Rcpp::VectorRTYPE::push_back(const T) [with T = Rcpp::traits::named_objectchar [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_objectchar [4]’ to ‘SEXP’ in initialization make: *** [file35af62e2.o] Error 1
Re: [Rcpp-devel] Problem with push_back to a list
On 25 October 2011 at 12:46, Michael Hannon wrote: | 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. You were very, very close to this existing example from the unit test file runit.Vector.R (which, as Lists are GenericVector objects, also contains lists): ,list_push_back=list( signature(x = list), 'List list(x) ; list.push_back( 10 ) ; list.push_back( bar, foo ) ; return list ; ') So with that it works if I write your example like this: - library(inline) code - ' Rcpp::List myList(rList); myList.push_back(10); myList.push_back(foo, bar); return myList; ' lfun - cxxfunction(signature(rList = list), body = code, plugin = Rcpp) - as can be seen below. Do not underestimate the usefulness of 750+ regression tests in 330+ functions that are run with every release. They do provide examples, even if they are a little hard to read at first :) Also, if an example does not compile, comment-out and simplify til it does. The templated code is finicky. I often split very complex expression into components as there is no shame in using temporary variables Dirk R library(inline) R R code - ' + Rcpp::List myList(rList); + myList.push_back(10); + myList.push_back(foo, bar); + return myList; + ' R R lfun - cxxfunction(signature(rList = list), + body = code, + plugin = Rcpp) R R ## ,list_push_back=list( R ## signature(x = list), R ## 'List list(x) ; R## list.push_back( 10 ) ; R## list.push_back( bar, foo ) ; R## return list ; R## ') R lfun(list(a=1,b=-1)) $a [1] 1 $b [1] -1 [[3]] [1] 10 $bar [1] foo R -- Outside of a dog, a book is a man's best friend. Inside of a dog, it is too dark to read. -- Groucho Marx ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
[Rcpp-devel] asarma::cx_double(x)
Dear list, I'm probably missing something basic, but I expected the following to work, library(RcppArmadillo) library(inline) fx - cxxfunction(signature(x = Rcomplex) , ' arma::cx_double y = asarma::cx_double(x); return wrap( y ) ; ', plugin = RcppArmadillo ) fx( 1+2i ) yet it fails to compile. I believe I need a conversion since arma does not know what to do with Rcomplex objects, e.g. multiplying x by i = arma::cx_double(0,1) yields error: no match for 'operator*' in 'x * i' I've successfully used cx_vec instead of cx_double, fx - cxxfunction(signature(x = Rcomplex) , ' arma::cx_vec y = asarma::cx_vec(x); const arma::cx_double i = arma::cx_double(0,1); return wrap( y * i ) ; ', plugin = RcppArmadillo ) fx( 1+2i ) Does this make sense? Best regards, baptiste ___ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel