C++ vector, structure, class in R extension

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

C++ vector, structure, class in R extension

This post has NOT been accepted by the mailing list yet.
I don't know R but I know C++. I need to connect exiting C++ application to R. I read Writing R extension manual and other helpers. I made simple connection tests  with .C(), .Call(), RCpp .Call(). But I didn't find a table or set of examples with relationships between R types and complex C/C++ types.

In my case I need to use
- STL vector with double
- C/C++ structure or class which have double, integer, and character array (or STL string)
- STL vector with structure or class

Also it is not clear how to use PROTECT - UNPROTECT functions if it is not mistakes in Writing R extension (see example from page 111 below). Maybe UNPROTECT(1) instead of UNPROTECT(4)? Similar issue on page 110.

Thanks, Andrey.

#include <R.h>
#include <Rinternals.h>
SEXP ans, dim, dimnames, class;
class = PROTECT(allocVector(STRSXP, 1));
SET_STRING_ELT(class, 0, mkChar("mat"));
classgets(ans, class);
return ans;