You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to convert a package from Rcpp to cpp11 since we need no more than a data passing interface.
While doing some simple tests, i encountered some problems regarding the method r_vector<T>::push_back(const named_arg&). I haven't been able to test with all types, so I'll only provide examples with cpp11::list.
Not really a problem but just a seemingly inconsistent behavior between constructors taking std::initializer_list of SEXP and named_arg:
cpp11::cpp_function('list testCpp11() { writable::list res_1({"named"_nm = "value"}); // conversion during the construction of named_arg writable::list res_2({as_sexp("unnamed_value")}); // require SEXP return res_1;}')
print(testCpp11())
#> $named#> [1] "value"
When trying to push_back to an initialized list:
# 2.1 push_back an unnamed value to a named list, okcpp11::cpp_function('list testCpp11() { writable::list named_list({"named"_nm = "value"}); named_list.push_back(as_sexp("unnamed_value")); return named_list;}')
print(testCpp11())
#> $named#> [1] "value"#> [[2]]#> [1] "unnamed_value"
# 2.2 push_back a named value to a named list, name is missingcpp11::cpp_function('list testCpp11() { writable::list named_list({"named"_nm = "value"}); named_list.push_back("another_named"_nm = "value"); return named_list;}')
print(testCpp11())
#> $named#> [1] "value"#> [[2]]#> [1] "value"
# 2.3 push_back an unnamed value to an unnamed list, okcpp11::cpp_function('list testCpp11() { writable::list unnamed_list({as_sexp("unnamed_value")}); unnamed_list.push_back(as_sexp("unnamed_value")); return unnamed_list;}')
print(testCpp11())
#> [[1]]#> [1] "unnamed_value"#> [[2]]#> [1] "unnamed_value"
# 2.4 push_back a named value to an unnamed list, errorcpp11::cpp_function('list testCpp11() { writable::list unnamed_list({as_sexp("unnamed_value")}); unnamed_list.push_back("named"_nm = "value"); return unnamed_list;}')
print(testCpp11())
#> Error in testCpp11() :#> Invalid input type, expected 'character' actual 'NULL'
When trying to push_back to an empty list:
# 3.1 push_back an unnamed value to an empty list, okcpp11::cpp_function('list testCpp11() { writable::list empty_list; empty_list.push_back(as_sexp("unnamed_value")); return empty_list;}')
print(testCpp11())
#> [[1]]#> [1] "unnamed_value"
# 3.2 push_back a named value to an empty list, errorcpp11::cpp_function('list testCpp11() { writable::list empty_list; empty_list.push_back("named"_nm = "value"); return empty_list;}')
print(testCpp11())
#> Error in testCpp11() :#> Invalid input type, expected 'character' actual 'NULL'
My questions are:
Are the results of test 2.2, 2.4, 3.2 intended behavior ?
Concerning what we actually need in our package, is there a way to push_back a named value to a named list without losing the value name (as shown in 2.2) ?
Also I'd like to request a feature to enable as_sexp for Container<Container<T>> (maybe with the conversion to list of list).
Thank you !
The text was updated successfully, but these errors were encountered:
Hi @jimhester , thanks for the quick fix for 2. and 3.. As for 1., with a closer look there are actually some problems with the interaction between the class named_arg and push_back for other types. I'll open another issue for that.
Now i'd like to ask for your thoughts about list as_sexp(Container<Container<T>>);. Should I open a feature request issue for that, or is it not going to be considered for now ?
I'd like to convert a package from Rcpp to cpp11 since we need no more than a data passing interface.
While doing some simple tests, i encountered some problems regarding the method
r_vector<T>::push_back(const named_arg&)
. I haven't been able to test with all types, so I'll only provide examples withcpp11::list
.std::initializer_list
ofSEXP
andnamed_arg
:push_back
to an initializedlist
:push_back
to an empty list:My questions are:
Also I'd like to request a feature to enable
as_sexp
forContainer<Container<T>>
(maybe with the conversion to list of list).Thank you !
The text was updated successfully, but these errors were encountered: