Skip to content

Commit

Permalink
Added comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
NicChr committed Oct 10, 2024
1 parent 329ea11 commit 3ff7071
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,19 @@ SEXP r_copy(SEXP x){
return Rf_duplicate(x);
}

// Shallow copy here means that a
// new list is created and
// all attributes are deep-copied
SEXP shallow_copy(SEXP x){
if (TYPEOF(x) != VECSXP){
Rf_error("Can only shallow copy lists");
}
R_xlen_t n = Rf_xlength(x);
SEXP out = Rf_protect(Rf_allocVector(VECSXP, n));
cpp_copy_attributes(x, out);
const SEXP *p_x = VECTOR_PTR_RO(x);
for (R_xlen_t i = 0; i < n; ++i){
SET_VECTOR_ELT(out, i, VECTOR_ELT(x, i));
SET_VECTOR_ELT(out, i, p_x[i]);
}
Rf_unprotect(1);
return out;
Expand Down

0 comments on commit 3ff7071

Please sign in to comment.