[Rcpp-devel] module can't expose std::map as a field?

Dirk Eddelbuettel edd at debian.org
Tue Dec 20 22:42:41 CET 2011


Hi Yasir,

On 20 December 2011 at 16:16, Yasir Suhail wrote:
| I saw at http://www.r-bloggers.com/rcpp-0-7-5-2/ that std::map can be
| exposed to R since Rcpp 0.7.5.2.

Re-reading the 0.7.5 NEWS entry:

0.7.5   2010-02-08

    o   wrap has been much improved. wrappable types now are :
        - primitive types : int, double, Rbyte, Rcomplex, float, bool
        - std::string
        - STL containers which have iterators over wrappable types:
          (e.g. std::vector<T>, std::deque<T>, std::list<T>, etc ...). 
        - STL maps keyed by std::string, e.g std::map<std::string,T>
        - classes that have implicit conversion to SEXP
        - classes for which the wrap template if fully or partly specialized
        This allows composition, so for example this class is wrappable: 
        std::vector< std::map<std::string,T> > (if T is wrappable)
        
   [...]

it becomes clear that you may have misunderstood.  The entry above talks
about Rcpp::wrap() which is used to send different C++ data structures back
to R.  No more, no less.
 
| I changed the skeleton module package to add a field:
| class World {
| public:
|     World() : msg("hello"){}
|     void set(std::string msg) { this->msg = msg; }
|     std::string greet() { return msg; }
|     std::map<std::string,int> myMap;
| private:
|     std::string msg;
| };

I am not sure we ever said anything about map inside Rcpp modules.  It could
work, or it could fail, but there is no relation to what is above.
  
| and then expose it as:
| 
| 	class_<World>( "World" )
| 	    // expose the default constructor
| 	    .constructor()
| 		.method( "greet", &World::greet , "get the message" )
| 		.method( "set", &World::set     , "set the message" )
| 		.field("myMap", &World::myMap)
| 	;

I have not worked much with .field() declarations for Modules so I'll pass here.

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


More information about the Rcpp-devel mailing list