@@ -32,8 +32,8 @@ namespace internal{
3232 DimNameProxy (SEXP data, int dim): data_(data), dim_(dim) {}
3333 DimNameProxy (DimNameProxy const & other):
3434 data_ (other.data_), dim_(other.dim_) {}
35-
36- inline DimNameProxy& operator = (SEXP other) {
35+
36+ inline DimNameProxy& assign (SEXP other) {
3737 SEXP dims = Rf_getAttrib (data_, R_DimSymbol);
3838 if (INTEGER (dims)[dim_] != Rf_length (other)) {
3939 stop (" dimension extent is '%d' while length of names is '%d'" , INTEGER (dims)[dim_], Rf_length (other));
@@ -47,27 +47,16 @@ namespace internal{
4747 SET_VECTOR_ELT (dimnames, dim_, other);
4848 }
4949 return *this ;
50+ }
51+
52+ inline DimNameProxy& operator =(SEXP other) {
53+ return assign (other);
5054 }
5155
5256 inline DimNameProxy& operator =(const DimNameProxy& other) {
53- SEXP dims = Rf_getAttrib (data_, R_DimSymbol);
54- if (INTEGER (dims)[dim_] != INTEGER (dims)[other.dim_ ]) {
55- stop (" dimension extent is '%d' while length of names is '%d'" , INTEGER (dims)[dim_], INTEGER (dims)[other.dim_ ]);
56- }
57- SEXP dimnames = Rf_getAttrib (data_, R_DimNamesSymbol);
58- SEXP other_dimnames = SEXP (other);
59- if (Rf_isNull (dimnames)) {
60- Shield<SEXP> new_dimnames (Rf_allocVector (VECSXP, Rf_length (dims)));
61- SET_VECTOR_ELT (new_dimnames, dim_, other_dimnames);
62- Rf_setAttrib (data_, R_DimNamesSymbol, new_dimnames);
63- } else {
64- SET_VECTOR_ELT (dimnames, dim_, other_dimnames);
65- }
66- return *this ;
57+ return assign (SEXP (other));
6758 }
6859
69-
70-
7160 inline operator SEXP () const {
7261 SEXP dimnames = Rf_getAttrib (data_, R_DimNamesSymbol);
7362 return Rf_isNull (dimnames) ? (R_NilValue) : (VECTOR_ELT (dimnames, dim_));
0 commit comments