Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
c9def8e
roxygen: restore roxygen unit tests and helpers (single commit)
pachadotdev Sep 18, 2025
00bd129
Correctly set dimnames for matrices
pachadotdev Sep 18, 2025
b138ff8
ordered and unordered C++ maps are converted to R lists - replaces #437
pachadotdev Sep 18, 2025
96ac5e2
remove roxygen changes, that is a different PR
pachadotdev Sep 18, 2025
11ac825
copy complex numbers/vectors/matrices from R to C++ and viceversa - r…
pachadotdev Sep 18, 2025
d9a03d3
almost there
pachadotdev Sep 18, 2025
9662aa7
fix cplx len
pachadotdev Sep 18, 2025
fe2bf32
simplify three false conditions for r_vector string (fix #431)
pachadotdev Sep 19, 2025
fc83025
Using vmaxget/vmaxset for as_cpp (implement #432)
pachadotdev Sep 19, 2025
fa90fd5
clang format
pachadotdev Sep 19, 2025
6d8426c
named_arg check with minimal changes
pachadotdev Sep 29, 2025
6739ade
Merge pull request #36 from pachadotdev/named_arg_utf8-clean
pachadotdev Nov 11, 2025
21e343b
Merge pull request #37 from pachadotdev/vmaxgetset-clean
pachadotdev Nov 11, 2025
3e1116e
Merge pull request #38 from pachadotdev/3Fto1T-clean
pachadotdev Nov 11, 2025
37e83e0
Merge branch 'cpp11-to-cpp4r' into complex-lean
pachadotdev Nov 11, 2025
933f214
Merge pull request #39 from pachadotdev/complex-lean
pachadotdev Nov 11, 2025
b7ce3ec
Merge branch 'cpp11-to-cpp4r' into map-to-list-clean
pachadotdev Nov 11, 2025
c8ce428
Merge pull request #40 from pachadotdev/map-to-list-clean
pachadotdev Nov 11, 2025
9b14d56
Merge branch 'cpp11-to-cpp4r' into matrix_attr-clean
pachadotdev Nov 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@ all:
@Rscript -e 'devtools::load_all("cpp11test")'
@echo "make: Leaving directory 'cpp11test/src'"

install:
@Rscript -e 'devtools::document()'
@Rscript -e 'devtools::install()'

test: all
@echo "make: Entering directory 'cpp11test/tests/testthat'"
@echo "make: Entering directory 'cpp11test'"
@Rscript -e 'devtools::document("cpp11test")'
@Rscript -e 'devtools::test("cpp11test")'
@echo "make: Leaving directory 'cpp11test/tests/testthat'"

Expand Down
2 changes: 1 addition & 1 deletion cpp11test/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ Suggests:
xml2
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.1
RoxygenNote: 7.3.2
60 changes: 60 additions & 0 deletions cpp11test/R/cpp11.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,22 @@ grow_ <- function(n) {
.Call(`_cpp11test_grow_`, n)
}

grow_cplx_ <- function(n) {
.Call(`_cpp11test_grow_cplx_`, n)
}

cpp11_insert_ <- function(num_sxp) {
.Call(`_cpp11test_cpp11_insert_`, num_sxp)
}

ordered_map_to_list_ <- function(x) {
.Call(`_cpp11test_ordered_map_to_list_`, x)
}

unordered_map_to_list_ <- function(x) {
.Call(`_cpp11test_unordered_map_to_list_`, x)
}

gibbs_cpp <- function(N, thin) {
.Call(`_cpp11test_gibbs_cpp`, N, thin)
}
Expand All @@ -108,6 +120,18 @@ row_sums <- function(x) {
.Call(`_cpp11test_row_sums`, x)
}

mat_mat_copy_dimnames <- function(x) {
.Call(`_cpp11test_mat_mat_copy_dimnames`, x)
}

mat_sexp_copy_dimnames <- function(x) {
.Call(`_cpp11test_mat_sexp_copy_dimnames`, x)
}

mat_mat_create_dimnames <- function() {
.Call(`_cpp11test_mat_mat_create_dimnames`)
}

col_sums <- function(x) {
.Call(`_cpp11test_col_sums`, x)
}
Expand Down Expand Up @@ -196,6 +220,42 @@ sum_dbl_accumulate2_ <- function(x_sxp) {
.Call(`_cpp11test_sum_dbl_accumulate2_`, x_sxp)
}

sum_cplx_for_ <- function(x) {
.Call(`_cpp11test_sum_cplx_for_`, x)
}

sum_cplx_for_2_ <- function(x) {
.Call(`_cpp11test_sum_cplx_for_2_`, x)
}

sum_cplx_for_3_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_3_`, x_sxp)
}

sum_cplx_for_4_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_4_`, x_sxp)
}

sum_cplx_for_5_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_5_`, x_sxp)
}

sum_cplx_for_6_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for_6_`, x_sxp)
}

sum_cplx_foreach_ <- function(x) {
.Call(`_cpp11test_sum_cplx_foreach_`, x)
}

sum_cplx_accumulate_ <- function(x) {
.Call(`_cpp11test_sum_cplx_accumulate_`, x)
}

sum_cplx_for2_ <- function(x_sxp) {
.Call(`_cpp11test_sum_cplx_for2_`, x_sxp)
}

sum_int_for_ <- function(x) {
.Call(`_cpp11test_sum_int_for_`, x)
}
Expand Down
176 changes: 176 additions & 0 deletions cpp11test/src/cpp11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,34 @@ extern "C" SEXP _cpp11test_grow_(SEXP n) {
return cpp11::as_sexp(grow_(cpp11::as_cpp<cpp11::decay_t<R_xlen_t>>(n)));
END_CPP11
}
// grow.cpp
cpp11::writable::complexes grow_cplx_(R_xlen_t n);
extern "C" SEXP _cpp11test_grow_cplx_(SEXP n) {
BEGIN_CPP11
return cpp11::as_sexp(grow_cplx_(cpp11::as_cpp<cpp11::decay_t<R_xlen_t>>(n)));
END_CPP11
}
// insert.cpp
SEXP cpp11_insert_(SEXP num_sxp);
extern "C" SEXP _cpp11test_cpp11_insert_(SEXP num_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(cpp11_insert_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(num_sxp)));
END_CPP11
}
// map.cpp
SEXP ordered_map_to_list_(cpp11::doubles x);
extern "C" SEXP _cpp11test_ordered_map_to_list_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(ordered_map_to_list_(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(x)));
END_CPP11
}
// map.cpp
SEXP unordered_map_to_list_(cpp11::doubles x);
extern "C" SEXP _cpp11test_unordered_map_to_list_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(unordered_map_to_list_(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles>>(x)));
END_CPP11
}
// matrix.cpp
SEXP gibbs_cpp(int N, int thin);
extern "C" SEXP _cpp11test_gibbs_cpp(SEXP N, SEXP thin) {
Expand Down Expand Up @@ -209,6 +230,27 @@ extern "C" SEXP _cpp11test_row_sums(SEXP x) {
END_CPP11
}
// matrix.cpp
cpp11::doubles_matrix<> mat_mat_copy_dimnames(cpp11::doubles_matrix<> x);
extern "C" SEXP _cpp11test_mat_mat_copy_dimnames(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(mat_mat_copy_dimnames(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles_matrix<>>>(x)));
END_CPP11
}
// matrix.cpp
SEXP mat_sexp_copy_dimnames(cpp11::doubles_matrix<> x);
extern "C" SEXP _cpp11test_mat_sexp_copy_dimnames(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(mat_sexp_copy_dimnames(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles_matrix<>>>(x)));
END_CPP11
}
// matrix.cpp
cpp11::doubles_matrix<> mat_mat_create_dimnames();
extern "C" SEXP _cpp11test_mat_mat_create_dimnames() {
BEGIN_CPP11
return cpp11::as_sexp(mat_mat_create_dimnames());
END_CPP11
}
// matrix.cpp
cpp11::doubles col_sums(cpp11::doubles_matrix<cpp11::by_column> x);
extern "C" SEXP _cpp11test_col_sums(SEXP x) {
BEGIN_CPP11
Expand Down Expand Up @@ -303,6 +345,55 @@ extern "C" SEXP _cpp11test_rcpp_release_(SEXP n) {
return R_NilValue;
END_CPP11
}
// roxygen1.cpp
double notroxcpp1_(double x);
extern "C" SEXP _cpp11test_notroxcpp1_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(notroxcpp1_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen1.cpp
double roxcpp2_(double x);
extern "C" SEXP _cpp11test_roxcpp2_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(roxcpp2_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen2.cpp
double roxcpp3_(double x);
extern "C" SEXP _cpp11test_roxcpp3_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(roxcpp3_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen2.cpp
double roxcpp4_(double x);
extern "C" SEXP _cpp11test_roxcpp4_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(roxcpp4_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen3.cpp
double roxcpp5_(double x);
extern "C" SEXP _cpp11test_roxcpp5_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(roxcpp5_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen3.cpp
double notroxcpp6_(double x);
extern "C" SEXP _cpp11test_notroxcpp6_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(notroxcpp6_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// roxygen3.cpp
double roxcpp7_(double x);
extern "C" SEXP _cpp11test_roxcpp7_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(roxcpp7_(cpp11::as_cpp<cpp11::decay_t<double>>(x)));
END_CPP11
}
// safe.cpp
SEXP cpp11_safe_(SEXP x_sxp);
extern "C" SEXP _cpp11test_cpp11_safe_(SEXP x_sxp) {
Expand Down Expand Up @@ -373,6 +464,69 @@ extern "C" SEXP _cpp11test_sum_dbl_accumulate2_(SEXP x_sxp) {
return cpp11::as_sexp(sum_dbl_accumulate2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
END_CPP11
}
// sum.cpp
cpp11::r_complex sum_cplx_for_(cpp11::complexes x);
extern "C" SEXP _cpp11test_sum_cplx_for_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
END_CPP11
}
// sum.cpp
cpp11::complexes sum_cplx_for_2_(cpp11::complexes x);
extern "C" SEXP _cpp11test_sum_cplx_for_2_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_2_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
END_CPP11
}
// sum.cpp
std::complex<double> sum_cplx_for_3_(cpp11::complexes x_sxp);
extern "C" SEXP _cpp11test_sum_cplx_for_3_(SEXP x_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_3_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x_sxp)));
END_CPP11
}
// sum.cpp
std::complex<double> sum_cplx_for_4_(SEXP x_sxp);
extern "C" SEXP _cpp11test_sum_cplx_for_4_(SEXP x_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_4_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
END_CPP11
}
// sum.cpp
SEXP sum_cplx_for_5_(SEXP x_sxp);
extern "C" SEXP _cpp11test_sum_cplx_for_5_(SEXP x_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_5_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
END_CPP11
}
// sum.cpp
cpp11::complexes sum_cplx_for_6_(SEXP x_sxp);
extern "C" SEXP _cpp11test_sum_cplx_for_6_(SEXP x_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for_6_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
END_CPP11
}
// sum.cpp
std::complex<double> sum_cplx_foreach_(cpp11::complexes x);
extern "C" SEXP _cpp11test_sum_cplx_foreach_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_foreach_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
END_CPP11
}
// sum.cpp
std::complex<double> sum_cplx_accumulate_(cpp11::complexes x);
extern "C" SEXP _cpp11test_sum_cplx_accumulate_(SEXP x) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_accumulate_(cpp11::as_cpp<cpp11::decay_t<cpp11::complexes>>(x)));
END_CPP11
}
// sum.cpp
std::complex<double> sum_cplx_for2_(SEXP x_sxp);
extern "C" SEXP _cpp11test_sum_cplx_for2_(SEXP x_sxp) {
BEGIN_CPP11
return cpp11::as_sexp(sum_cplx_for2_(cpp11::as_cpp<cpp11::decay_t<SEXP>>(x_sxp)));
END_CPP11
}
// sum_int.cpp
double sum_int_for_(cpp11::integers x);
extern "C" SEXP _cpp11test_sum_int_for_(SEXP x) {
Expand Down Expand Up @@ -488,6 +642,10 @@ static const R_CallMethodDef CallEntries[] = {
{"_cpp11test_gibbs_rcpp", (DL_FUNC) &_cpp11test_gibbs_rcpp, 2},
{"_cpp11test_gibbs_rcpp2", (DL_FUNC) &_cpp11test_gibbs_rcpp2, 2},
{"_cpp11test_grow_", (DL_FUNC) &_cpp11test_grow_, 1},
{"_cpp11test_mat_mat_copy_dimnames", (DL_FUNC) &_cpp11test_mat_mat_copy_dimnames, 1},
{"_cpp11test_mat_mat_create_dimnames", (DL_FUNC) &_cpp11test_mat_mat_create_dimnames, 0},
{"_cpp11test_mat_sexp_copy_dimnames", (DL_FUNC) &_cpp11test_mat_sexp_copy_dimnames, 1},
{"_cpp11test_grow_cplx_", (DL_FUNC) &_cpp11test_grow_cplx_, 1},
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},
Expand All @@ -500,6 +658,9 @@ static const R_CallMethodDef CallEntries[] = {
{"_cpp11test_my_warning_n1", (DL_FUNC) &_cpp11test_my_warning_n1, 1},
{"_cpp11test_my_warning_n1fmt", (DL_FUNC) &_cpp11test_my_warning_n1fmt, 1},
{"_cpp11test_my_warning_n2fmt", (DL_FUNC) &_cpp11test_my_warning_n2fmt, 2},
{"_cpp11test_ordered_map_to_list_", (DL_FUNC) &_cpp11test_ordered_map_to_list_, 1},
{"_cpp11test_notroxcpp1_", (DL_FUNC) &_cpp11test_notroxcpp1_, 1},
{"_cpp11test_notroxcpp6_", (DL_FUNC) &_cpp11test_notroxcpp6_, 1},
{"_cpp11test_protect_many_", (DL_FUNC) &_cpp11test_protect_many_, 1},
{"_cpp11test_protect_many_cpp11_", (DL_FUNC) &_cpp11test_protect_many_cpp11_, 1},
{"_cpp11test_protect_many_preserve_", (DL_FUNC) &_cpp11test_protect_many_preserve_, 1},
Expand All @@ -518,8 +679,22 @@ static const R_CallMethodDef CallEntries[] = {
{"_cpp11test_rcpp_sum_int_for_", (DL_FUNC) &_cpp11test_rcpp_sum_int_for_, 1},
{"_cpp11test_remove_altrep", (DL_FUNC) &_cpp11test_remove_altrep, 1},
{"_cpp11test_row_sums", (DL_FUNC) &_cpp11test_row_sums, 1},
{"_cpp11test_roxcpp2_", (DL_FUNC) &_cpp11test_roxcpp2_, 1},
{"_cpp11test_roxcpp3_", (DL_FUNC) &_cpp11test_roxcpp3_, 1},
{"_cpp11test_roxcpp4_", (DL_FUNC) &_cpp11test_roxcpp4_, 1},
{"_cpp11test_roxcpp5_", (DL_FUNC) &_cpp11test_roxcpp5_, 1},
{"_cpp11test_roxcpp7_", (DL_FUNC) &_cpp11test_roxcpp7_, 1},
{"_cpp11test_string_proxy_assignment_", (DL_FUNC) &_cpp11test_string_proxy_assignment_, 0},
{"_cpp11test_string_push_back_", (DL_FUNC) &_cpp11test_string_push_back_, 0},
{"_cpp11test_sum_cplx_accumulate_", (DL_FUNC) &_cpp11test_sum_cplx_accumulate_, 1},
{"_cpp11test_sum_cplx_for2_", (DL_FUNC) &_cpp11test_sum_cplx_for2_, 1},
{"_cpp11test_sum_cplx_for_", (DL_FUNC) &_cpp11test_sum_cplx_for_, 1},
{"_cpp11test_sum_cplx_for_2_", (DL_FUNC) &_cpp11test_sum_cplx_for_2_, 1},
{"_cpp11test_sum_cplx_for_3_", (DL_FUNC) &_cpp11test_sum_cplx_for_3_, 1},
{"_cpp11test_sum_cplx_for_4_", (DL_FUNC) &_cpp11test_sum_cplx_for_4_, 1},
{"_cpp11test_sum_cplx_for_5_", (DL_FUNC) &_cpp11test_sum_cplx_for_5_, 1},
{"_cpp11test_sum_cplx_for_6_", (DL_FUNC) &_cpp11test_sum_cplx_for_6_, 1},
{"_cpp11test_sum_cplx_foreach_", (DL_FUNC) &_cpp11test_sum_cplx_foreach_, 1},
{"_cpp11test_sum_dbl_accumulate2_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate2_, 1},
{"_cpp11test_sum_dbl_accumulate_", (DL_FUNC) &_cpp11test_sum_dbl_accumulate_, 1},
{"_cpp11test_sum_dbl_for2_", (DL_FUNC) &_cpp11test_sum_dbl_for2_, 1},
Expand All @@ -533,6 +708,7 @@ static const R_CallMethodDef CallEntries[] = {
{"_cpp11test_sum_int_foreach_", (DL_FUNC) &_cpp11test_sum_int_foreach_, 1},
{"_cpp11test_test_destruction_inner", (DL_FUNC) &_cpp11test_test_destruction_inner, 0},
{"_cpp11test_test_destruction_outer", (DL_FUNC) &_cpp11test_test_destruction_outer, 0},
{"_cpp11test_unordered_map_to_list_", (DL_FUNC) &_cpp11test_unordered_map_to_list_, 1},
{"_cpp11test_upper_bound", (DL_FUNC) &_cpp11test_upper_bound, 2},
{"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 1},
{NULL, NULL, 0}
Expand Down
12 changes: 12 additions & 0 deletions cpp11test/src/grow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "cpp11/complexes.hpp"
#include "cpp11/doubles.hpp"

[[cpp11::register]] cpp11::writable::doubles grow_(R_xlen_t n) {
Expand All @@ -9,3 +10,14 @@

return x;
}

[[cpp11::register]] cpp11::writable::complexes grow_cplx_(R_xlen_t n) {
cpp11::writable::complexes x;
R_xlen_t i = 0;
while (i < n) {
x.push_back(std::complex<double>(i, i));
i++;
}

return x;
}
20 changes: 20 additions & 0 deletions cpp11test/src/map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "cpp11/as.hpp"
#include "cpp11/doubles.hpp"

[[cpp11::register]] SEXP ordered_map_to_list_(cpp11::doubles x) {
std::map<double, int> counts;
int n = x.size();
for (int i = 0; i < n; i++) {
counts[x[i]]++;
}
return cpp11::as_sexp(counts);
}

[[cpp11::register]] SEXP unordered_map_to_list_(cpp11::doubles x) {
std::unordered_map<double, int> counts;
int n = x.size();
for (int i = 0; i < n; i++) {
counts[x[i]]++;
}
return cpp11::as_sexp(counts);
}
Loading
Loading