Skip to content
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

Idiomatic way to cast or convert between different r_vector types #264

Open
vspinu opened this issue Feb 18, 2022 · 0 comments
Open

Idiomatic way to cast or convert between different r_vector types #264

vspinu opened this issue Feb 18, 2022 · 0 comments

Comments

@vspinu
Copy link
Contributor

vspinu commented Feb 18, 2022

The following conversions results in a run time error Invalid input type, expected 'integer' actual 'logical'

// cpp11::logicals val
cpp11::integers ints(val);
cpp11::integers ints = cpp11::as_cpp<cpp11::integers>(val);

It's not clear to me why logicals cannot be re-interpreted as integers. After all it's the same internal representation.

What is an idiomatic way to convert within cpp11 when converting at R level is not an option? Is it enough to cpp11::integers X2(Rf_coerceVector(X, INTSXP));, or do I still need to protect the converted vector?

It would be great if this information could be added to the conversion section of the vignette.

Thanks!
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant