1 #ifndef VCTRS_DIM_H 2 #define VCTRS_DIM_H 3 4 #include "vctrs.h" 5 #include "utils.h" 6 7 // These versions return NULL and 0 for bare vectors. 8 // This is useful to distinguish them from 1D arrays. vec_bare_dim(SEXP x)9static inline SEXP vec_bare_dim(SEXP x) { 10 return r_dim(x); 11 } vec_bare_dim_n(SEXP x)12static inline R_len_t vec_bare_dim_n(SEXP x) { 13 return Rf_length(vec_bare_dim(x)); 14 } 15 16 vec_dim(SEXP x)17static inline SEXP vec_dim(SEXP x) { 18 SEXP dim = vec_bare_dim(x); 19 20 if (dim == R_NilValue) { 21 dim = r_int(Rf_length(x)); 22 } 23 24 return dim; 25 } 26 vec_dim_n(SEXP x)27static inline R_len_t vec_dim_n(SEXP x) { 28 SEXP dim = vec_bare_dim(x); 29 30 if (dim == R_NilValue) { 31 return 1; 32 } 33 34 return Rf_length(dim); 35 } 36 37 has_dim(SEXP x)38static inline bool has_dim(SEXP x) { 39 return ATTRIB(x) != R_NilValue && r_dim(x) != R_NilValue; 40 } 41 42 #endif 43