Skip to content
Prev 6342 / 10988 Next

[Rcpp-devel] Returning an element from a List with its attributes?

Hi Tal,

In your example, note that x[[1]] is not a list; hence it must first be
coerced to a list, and attributes are lost in this conversion. This is
fairly standard in R code; eg x <- 1; attr(x, "animal") <- "cat"; x;
as.list(x), so you can't blame Rcpp for being consistent with R here.

The onus is on you to be careful with your types when setting attributes.
You should assume they are lost if you do any conversion. Indeed, the
non-standard attributes are very brittle.

That said, if you want the size of an RObject, there is always the C API to
fall back on: Rf_length(x) gives you the length of the object, agnostic to
its type.

-Kevin
On Tue, Aug 20, 2013 at 2:31 PM, Tal Galili <tal.galili at gmail.com> wrote:

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