Closed
Description
At the moment, coersion from an R numeric scalar to an int
works nicely - doubles are converted to integers if they are representable as integers without truncation of the decimal part. However, the same is not true of a vector of numeric values into cpp11::integers
:
cpp11::cpp_source(
code = c(
"#include <cpp11.hpp>",
"[[cpp11::register]]",
"void test(int x, cpp11::integers y) {",
"}"))
test(1L, 1L) # works, as expected
test(1, 1L) # works, due to the double -> int conversion
test(1L, 1) # fails with error "Invalid input type, expected 'integer' actual 'double'"
The same problem impacts passing a vector of integers to a function expecting doubles:
cpp11::cpp_source(
code = c(
"#include <cpp11.hpp>",
"[[cpp11::register]]",
"void test2(cpp11::doubles y) {",
"}"))
test2(seq_len(4))
#> Error in test2(seq_len(4)) :
#> Invalid input type, expected 'double' actual 'integer'
It would be nice if it is possible to relax this as practically this requires additional wrappers to the be added in either the C++ or the R code, especially as the name of the problematic variable can't be easily found from the error message.