{"action":"created","issue":{"url":"https://api.github.com/repos/RcppCore/Rcpp/issues/379","labels_url":"https://api.github.com/repos/RcppCore/Rcpp/issues/379/labels{/name}","comments_url":"https://api.github.com/repos/RcppCore/Rcpp/issues/379/comments","events_url":"https://api.github.com/repos/RcppCore/Rcpp/issues/379/events","html_url":"https://github.com/RcppCore/Rcpp/issues/379","id":110056548,"number":379,"title":"How to Get Pointer of Underlying Object of Rcpp Class","user":{"login":"tqchen","id":2577440,"avatar_url":"https://avatars.githubusercontent.com/u/2577440?v=3","gravatar_id":"","url":"https://api.github.com/users/tqchen","html_url":"https://github.com/tqchen","followers_url":"https://api.github.com/users/tqchen/followers","following_url":"https://api.github.com/users/tqchen/following{/other_user}","gists_url":"https://api.github.com/users/tqchen/gists{/gist_id}","starred_url":"https://api.github.com/users/tqchen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tqchen/subscriptions","organizations_url":"https://api.github.com/users/tqchen/orgs","repos_url":"https://api.github.com/users/tqchen/repos","events_url":"https://api.github.com/users/tqchen/events{/privacy}","received_events_url":"https://api.github.com/users/tqchen/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-10-06T17:18:14Z","updated_at":"2015-10-06T20:07:32Z","closed_at":"2015-10-06T17:51:10Z","body":"The Rcpp class offers a great way to wrap a S4 class from existing class. However, we find the following use-case, where we need to get the underlying pointer from Rcpp Class object. As well as constructing a new Rcpp class from C++ side\r\n\r\n```c++\r\nclass MyClass {\r\npublic:\r\n   static void SaveList(SEXP list, const std::string& filename) {\r\n          Rcpp::List data_lst(list);\r\n          std::vector<MyClass *> internals(data_lst[i]);\r\n          for (size_t i = 0; i < data_lst.size(); ++i) {\r\n               SEXP obj = data_lst[i];\r\n               // Need to Get internal pointers from S4 MyClass object\r\n               internals[i] = GetPtr<MyClass>(obj);\r\n          }\r\n          SomeRealSave(internals, filename);\r\n   }\r\n   static void LoadList(const std::string& filename) {\r\n          std::vector<MyClass > internals;\r\n          SomeReadLoad(&internals);\r\n          Rcpp::List out(internals.size());\r\n          for (size_t i = 0; i < internals.size(); ++i) {\r\n              // need to construct a MyClass object from C++ side\r\n              out[i] = MyClassConstructor(internals[i]);\r\n          }\r\n         return out;\r\n   }\r\n};\r\n\r\nRCPP_MODULE(MyClass) {\r\n     class_<MyClass>(\"MyClass\");\r\n\r\n     function(\"save.myclass.list\", &Array::SaveList);\r\n     function(\"load.myclass.list\", &Array::LoadList);\r\n}\r\n```\r\n\r\nI realized that this is possible to wrap our own struct by external pointer, but seems that duplicates what Rcpp class offers. I could not find \"official solution\" to this problem, so I am posting an issue here."},"comment":{"url":"https://api.github.com/repos/RcppCore/Rcpp/issues/comments/145982812","html_url":"https://github.com/RcppCore/Rcpp/issues/379#issuecomment-145982812","issue_url":"https://api.github.com/repos/RcppCore/Rcpp/issues/379","id":145982812,"user":{"login":"eddelbuettel","id":673121,"avatar_url":"https://avatars.githubusercontent.com/u/673121?v=3","gravatar_id":"","url":"https://api.github.com/users/eddelbuettel","html_url":"https://github.com/eddelbuettel","followers_url":"https://api.github.com/users/eddelbuettel/followers","following_url":"https://api.github.com/users/eddelbuettel/following{/other_user}","gists_url":"https://api.github.com/users/eddelbuettel/gists{/gist_id}","starred_url":"https://api.github.com/users/eddelbuettel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eddelbuettel/subscriptions","organizations_url":"https://api.github.com/users/eddelbuettel/orgs","repos_url":"https://api.github.com/users/eddelbuettel/repos","events_url":"https://api.github.com/users/eddelbuettel/events{/privacy}","received_events_url":"https://api.github.com/users/eddelbuettel/received_events","type":"User","site_admin":false},"created_at":"2015-10-06T20:07:32Z","updated_at":"2015-10-06T20:07:32Z","body":"I am not seeing it.  Posting is restricted to those registered, and requires posting from the same address."}}