digEmAll/stdvectors

vec_to_stdvector (just for completeness)?

talgalili opened this issue · 1 comments

Maybe there is room to add:


vec_to_stdvector <- function(x) {
	n <- length(x)
	new_x <- stdvectorCreate(type=typeof(x), n)
	for(i in 1:n) stdvectorPushBack(new_x,x[i]) 
	new_x
}

This can then allow more interesting work with stdvectorReplace and stdvectorSubset etc.

It's actually 2 lines to convert a R vector to stdvector. It's simply :

v <- 1:1e6 # vector to convert

sdv <- stdvectorCreate(type=typeof(v),length(v))
stdvectorPushBack(sdv,v)

The only caveat is that you can't use typeof if your vector is a list, because the necessary type is "any" and not "list" as returned by typeof.

Also, basically stdvector purpose is creating a R base vector in a loop etc, then to avoid the opposite behavior I prefer not to add that function :)