Skip to content

Commit 54efe8c

Browse files
committed
correctly set dimnames for matrices - replaces PR r-lib#428
1 parent c9def8e commit 54efe8c

File tree

16 files changed

+1442
-1683
lines changed

16 files changed

+1442
-1683
lines changed

cpp11test/R/cpp11.R

Lines changed: 12 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,18 @@ row_sums <- function(x) {
108108
.Call(`_cpp11test_row_sums`, x)
109109
}
110110

111+
mat_mat_copy_dimnames <- function(x) {
112+
.Call(`_cpp11test_mat_mat_copy_dimnames`, x)
113+
}
114+
115+
mat_sexp_copy_dimnames <- function(x) {
116+
.Call(`_cpp11test_mat_sexp_copy_dimnames`, x)
117+
}
118+
119+
mat_mat_create_dimnames <- function() {
120+
.Call(`_cpp11test_mat_mat_create_dimnames`)
121+
}
122+
111123
col_sums <- function(x) {
112124
.Call(`_cpp11test_col_sums`, x)
113125
}
@@ -156,34 +168,6 @@ rcpp_release_ <- function(n) {
156168
invisible(.Call(`_cpp11test_rcpp_release_`, n))
157169
}
158170

159-
notroxcpp1_ <- function(x) {
160-
.Call(`_cpp11test_notroxcpp1_`, x)
161-
}
162-
163-
roxcpp2_ <- function(x) {
164-
.Call(`_cpp11test_roxcpp2_`, x)
165-
}
166-
167-
roxcpp3_ <- function(x) {
168-
.Call(`_cpp11test_roxcpp3_`, x)
169-
}
170-
171-
roxcpp4_ <- function(x) {
172-
.Call(`_cpp11test_roxcpp4_`, x)
173-
}
174-
175-
roxcpp5_ <- function(x) {
176-
.Call(`_cpp11test_roxcpp5_`, x)
177-
}
178-
179-
notroxcpp6_ <- function(x) {
180-
.Call(`_cpp11test_notroxcpp6_`, x)
181-
}
182-
183-
roxcpp7_ <- function(x) {
184-
.Call(`_cpp11test_roxcpp7_`, x)
185-
}
186-
187171
cpp11_safe_ <- function(x_sxp) {
188172
.Call(`_cpp11test_cpp11_safe_`, x_sxp)
189173
}
@@ -196,26 +180,6 @@ string_push_back_ <- function() {
196180
.Call(`_cpp11test_string_push_back_`)
197181
}
198182

199-
grow_strings_cpp11_ <- function(n, seed) {
200-
.Call(`_cpp11test_grow_strings_cpp11_`, n, seed)
201-
}
202-
203-
grow_strings_rcpp_ <- function(n, seed) {
204-
.Call(`_cpp11test_grow_strings_rcpp_`, n, seed)
205-
}
206-
207-
grow_strings_manual_ <- function(n, seed) {
208-
.Call(`_cpp11test_grow_strings_manual_`, n, seed)
209-
}
210-
211-
assign_cpp11_ <- function(n, seed) {
212-
.Call(`_cpp11test_assign_cpp11_`, n, seed)
213-
}
214-
215-
assign_rcpp_ <- function(n, seed) {
216-
.Call(`_cpp11test_assign_rcpp_`, n, seed)
217-
}
218-
219183
sum_dbl_for_ <- function(x) {
220184
.Call(`_cpp11test_sum_dbl_for_`, x)
221185
}
@@ -284,14 +248,6 @@ rcpp_push_and_truncate_ <- function(size_sxp) {
284248
.Call(`_cpp11test_rcpp_push_and_truncate_`, size_sxp)
285249
}
286250

287-
nullable_extptr_1 <- function() {
288-
.Call(`_cpp11test_nullable_extptr_1`)
289-
}
290-
291-
nullable_extptr_2 <- function() {
292-
.Call(`_cpp11test_nullable_extptr_2`)
293-
}
294-
295251
test_destruction_inner <- function() {
296252
invisible(.Call(`_cpp11test_test_destruction_inner`))
297253
}

cpp11test/man/roxcpp2_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp3_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp4_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp5_.Rd

Lines changed: 0 additions & 17 deletions
This file was deleted.

cpp11test/man/roxcpp7_.Rd

Lines changed: 0 additions & 22 deletions
This file was deleted.

cpp11test/src/cpp11.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,27 @@ extern "C" SEXP _cpp11test_row_sums(SEXP x) {
209209
END_CPP11
210210
}
211211
// matrix.cpp
212+
cpp11::doubles_matrix<> mat_mat_copy_dimnames(cpp11::doubles_matrix<> x);
213+
extern "C" SEXP _cpp11test_mat_mat_copy_dimnames(SEXP x) {
214+
BEGIN_CPP11
215+
return cpp11::as_sexp(mat_mat_copy_dimnames(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles_matrix<>>>(x)));
216+
END_CPP11
217+
}
218+
// matrix.cpp
219+
SEXP mat_sexp_copy_dimnames(cpp11::doubles_matrix<> x);
220+
extern "C" SEXP _cpp11test_mat_sexp_copy_dimnames(SEXP x) {
221+
BEGIN_CPP11
222+
return cpp11::as_sexp(mat_sexp_copy_dimnames(cpp11::as_cpp<cpp11::decay_t<cpp11::doubles_matrix<>>>(x)));
223+
END_CPP11
224+
}
225+
// matrix.cpp
226+
cpp11::doubles_matrix<> mat_mat_create_dimnames();
227+
extern "C" SEXP _cpp11test_mat_mat_create_dimnames() {
228+
BEGIN_CPP11
229+
return cpp11::as_sexp(mat_mat_create_dimnames());
230+
END_CPP11
231+
}
232+
// matrix.cpp
212233
cpp11::doubles col_sums(cpp11::doubles_matrix<cpp11::by_column> x);
213234
extern "C" SEXP _cpp11test_col_sums(SEXP x) {
214235
BEGIN_CPP11
@@ -488,6 +509,9 @@ static const R_CallMethodDef CallEntries[] = {
488509
{"_cpp11test_gibbs_rcpp", (DL_FUNC) &_cpp11test_gibbs_rcpp, 2},
489510
{"_cpp11test_gibbs_rcpp2", (DL_FUNC) &_cpp11test_gibbs_rcpp2, 2},
490511
{"_cpp11test_grow_", (DL_FUNC) &_cpp11test_grow_, 1},
512+
{"_cpp11test_mat_mat_copy_dimnames", (DL_FUNC) &_cpp11test_mat_mat_copy_dimnames, 1},
513+
{"_cpp11test_mat_mat_create_dimnames", (DL_FUNC) &_cpp11test_mat_mat_create_dimnames, 0},
514+
{"_cpp11test_mat_sexp_copy_dimnames", (DL_FUNC) &_cpp11test_mat_sexp_copy_dimnames, 1},
491515
{"_cpp11test_my_message", (DL_FUNC) &_cpp11test_my_message, 2},
492516
{"_cpp11test_my_message_n1", (DL_FUNC) &_cpp11test_my_message_n1, 1},
493517
{"_cpp11test_my_message_n1fmt", (DL_FUNC) &_cpp11test_my_message_n1fmt, 1},

cpp11test/src/matrix.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include "cpp11/matrix.hpp"
22
#include "Rmath.h"
33
#include "cpp11/doubles.hpp"
4+
#include "cpp11/list.hpp"
5+
#include "cpp11/strings.hpp"
46
using namespace cpp11;
57

68
[[cpp11::register]] SEXP gibbs_cpp(int N, int thin) {
@@ -86,6 +88,40 @@ using namespace Rcpp;
8688
return sums;
8789
}
8890

91+
[[cpp11::register]] cpp11::doubles_matrix<> mat_mat_copy_dimnames(
92+
cpp11::doubles_matrix<> x) {
93+
cpp11::writable::doubles_matrix<> out = x;
94+
95+
out.attr("dimnames") = x.attr("dimnames");
96+
97+
return out;
98+
}
99+
100+
[[cpp11::register]] SEXP mat_sexp_copy_dimnames(cpp11::doubles_matrix<> x) {
101+
cpp11::writable::doubles_matrix<> out = x;
102+
103+
out.attr("dimnames") = x.attr("dimnames");
104+
105+
return out;
106+
}
107+
108+
[[cpp11::register]] cpp11::doubles_matrix<> mat_mat_create_dimnames() {
109+
cpp11::writable::doubles_matrix<> out(2, 2);
110+
111+
out(0, 0) = 1;
112+
out(0, 1) = 2;
113+
out(1, 0) = 3;
114+
out(1, 1) = 4;
115+
116+
cpp11::writable::list dimnames(2);
117+
dimnames[0] = cpp11::strings({"a", "b"});
118+
dimnames[1] = cpp11::strings({"c", "d"});
119+
120+
out.attr("dimnames") = dimnames;
121+
122+
return out;
123+
}
124+
89125
[[cpp11::register]] cpp11::doubles col_sums(cpp11::doubles_matrix<cpp11::by_column> x) {
90126
cpp11::writable::doubles sums(x.ncol());
91127

cpp11test/src/roxygen1.cpp

Lines changed: 0 additions & 22 deletions
This file was deleted.

cpp11test/src/roxygen2.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)