-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assigning an attribute to an empty vector in c++ produces an error #315
Comments
I find it useful as is - under the hood it means that cpp11 doesn't make new expressions for R to manage unless (explicitly) asked to. For what it's worth, an empty vector in cpp11 can be initialised with: cpp11::writable::doubles x(0);
// x <- numeric(0) |
Thank you for the quick response and clarification. However, your code won't compile on my machine, letting me know that cpp11::writable::doubles x((R_xlen_t)0); After this I was indeed able to set an attribute value; Maybe some attention to the initialisation of vectors could be given in one of the vignettes? |
Ah I forgot that zero can be used to initialise other types and that leads to ambiguity. Definitely something that should be documented. |
Thanks for your work on
cpp11
!Please consider the following. In c++ the code below will produce the error:
attempt to set an attribute on NULL
This would make sense when
x
actually is aNULL
, since in R the following code will produce the same error:However, I would expect the c++ code to behave as the following R code:
which works fine.
My question is: Is this expected behaviour from
cpp11
? If so what would be the recommended strategy to set an attribute to an empty vector (i.e., a vector of a defined type but length zero) in c++ usingcpp11
. If this is not expected behaviour, can it be fixed?My session looks like this:
The text was updated successfully, but these errors were encountered: