c++ - Rcpp How to change a value directly inside a R List -
i know how values list objet, , how create 1 within c function.
but change value in list given parameter , modification effective when exiting function.
some thing like:
void myfunc(sexp *lst) ' list mylist (lst) // make modification }
i need modify list within recursive loop.
thanks in advance daniel
there no magic. assign elements list
object, , modify:
r> rcpp::cppfunction("list foo(list l) { list l2 = l[0]; l2[1] = 42; return l2;} ") r> l <- list(list(0,1,2), 2:4, 3.3) r> foo(l) [[1]] [1] 0 [[2]] [1] 42 [[3]] [1] 2 r>
we pick first element (and know list
itself; there predicates testing). in list, set second element. can same returning original modified list:
r> rcpp::cppfunction("list bar(list l) { list l2 = l[0]; l2[1] = 42; return l;} ") r> l <- list(list(0,1,2), 2:4, 3.3) r> bar(l) [[1]] [[1]][[1]] [1] 0 [[1]][[2]] [1] 42 [[1]][[3]] [1] 2 [[2]] [1] 2 3 4 [[3]] [1] 3.3 r>
Comments
Post a Comment