[Rcpp-devel] wrap documentation?

Sokol Serguei serguei.sokol at gmail.com
Mon Apr 27 19:32:50 CEST 2020


Le 27/04/2020 à 18:55, Toby Hocking a écrit :
> Hi Dirk and Sokol, thanks for the responses.
> Dirk I was aware that the C/C++ output type of wrap is always SEXP, 
> but I my question was about the R type/class.
> Also thanks for the ref of the discussion in Sec 3.1 of the JSS 2011 
> article, which is pretty much what I was looking for, but it seems to 
> be incomplete. I can deduce from the example that std::vector becomes 
> a list in R, and std::map<string, int> becomes a named integer vector 
> in R, but I am looking for a list of all such conversions that have 
> currently been implemented.
> I guess there is no such documentation, and we should instead refer to 
> the source code as Seugeui pointed out?
> In that case I find it a bit problematic, because there are lots of 
> conversions that are possible, but not obvious upon inspection of 
> wrap.h. For example the std::vector -> R list conversion is not 
> obvious (I don't see any mention of std::vector in wrap.h actually).
Because std::vector can have any type of element, e.g. vector of 
vectors, the procedure has to be generic enough. So it is realized 
through iterators which are not exclusive for std::vector.
E.g. for vector of pairs <string, some_type> it is probably this 
procedure which will be called:
https://github.com/sgsokol/Rcpp/blob/acf8756a75a97ee203e261412a2ab3fa7d6e15c7/inst/include/Rcpp/internal/wrap.h#L334
It will produce a named list in R.

Best,
Serguei.



> As an Rcpp user I think it would be very helpful to have a list/table 
> that documents all the currently implemented conversions. Would that 
> be very difficult to write by hand / generate from the source code?
>
> On Sun, Apr 26, 2020 at 12:07 AM Sokol Serguei <sokol at insa-toulouse.fr 
> <mailto:sokol at insa-toulouse.fr>> wrote:
>
>     Le 26/04/2020 à 01:19, Dirk Eddelbuettel a écrit :
>     > On 25 April 2020 at 16:04, Toby Hocking wrote: | Hi, can someone
>     > please tell me where the return types of wrap are | documented? The
>     > _return_ value of a wrap() call is by definition always SEXP.
>     Just how
>     > the _input_ for as<>() converters is always a SEXP. For wrap(), see
>     > e.g. Section 3.1 of the JSS 2011 paper which ships as vignette
>     > Rcpp-jss-2011.pdf
>     To complete the Dirk's response, this gallery example can be of
>     some help:
>     https://gallery.rcpp.org/articles/custom-templated-wrap-and-as-for-seamingless-interfaces/
>
>     And as always, an ultimate place to clarify the trickiest
>     questions is
>     the code itself ;) :
>     https://github.com/sgsokol/Rcpp/blob/master/inst/include/Rcpp/internal/wrap.h
>
>     Best,
>     Serguei.
>
>
> _______________________________________________
> 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


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20200427/bb927c1c/attachment.html>


More information about the Rcpp-devel mailing list