[Rcpp-devel] Locating an Instance of a Reference Class in the Environment

Matthew Supernaw - NOAA Federal matthew.supernaw at noaa.gov
Fri Mar 24 18:08:10 CET 2023


I'm sure it's possible to do from the R side, however, the requirement is
to hide this from the end user and set the reference objects name to the
declared name from the R environment. If I view the environment in RStudio,
there is much more information available. ls() only returns a list of
objects by their declared name. I'm wondering how to get more details about
elements in the environment.

On Thu, Mar 23, 2023 at 6:03 PM Dirk Eddelbuettel <edd at debian.org> wrote:

>
> On 22 March 2023 at 13:31, Matthew Supernaw - NOAA Federal wrote:
> | I'm trying to get an instance of a reference class
> (vonBertalanffyInterface)
> | from the R environment with the following code:
> |
> | void SetName(vonBertalanffyInterface& v) {
> |
> |     Rcpp::Environment env = Rcpp::Environment::global_env();
> |     Rcpp::List l = Rcpp::as<Rcpp::List>(env.ls(true));
> |
> |     for (int i = 0; i < l.size(); i++) {
> |         std::cout << typeid (l[i]).name() << std::endl;
> |
> |         if(&v == l[i].get()){
> |             v.name Rcpp::as<std::string>(l[i]);
> |         }
> |     }
> | }
> |
> | The problem is that elements in the list are of type
> | N4Rcpp8internal13generic_proxyILi19ENS_15PreserveStorageEEE.
> |
> | I'm assuming that PreserveStorage is a wrapper class. Is there a way to
> | retrieve the reference class from the PreserveStorage object?
>
> Interesting question.  Can you do it in plain R (once you created the
> object) ?
>
> Dirk
>
> --
> dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
>


-- 
Matthew Supernaw
*Scientific Software Developer*
*National Oceanic and Atmospheric Administration*
*Office Of Science and Technology*
*NOAA Fisheries | *U.S. Department of Commerce
Phone 248 - 396 - 7797
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20230324/7f165273/attachment.html>


More information about the Rcpp-devel mailing list