-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vec_slice2()
and vec_assign2()
#1228
base: add-chop2
Are you sure you want to change the base?
Conversation
i <- vec_as_location2(i, vec_size(x)) | ||
.subset2(x, i) | ||
} else { | ||
out <- vec_slice(x, i) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use vec_as_location2()
on i
?
value <- list(value) | ||
} | ||
|
||
vec_assign(x, i, value, x_arg = x_arg, value_arg = value_arg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use vec_as_location2()
on i
?
Should |
Branched from #1226.
Following
vec_chop2()
andvec_map()
, this further explores the idea of "extracting" variants of vctrs primitives.With atomic vectors,
vec_slice2()
andvec_assign2()
are equivalent tovec_slice()
andvec_assign()
. The only difference is thatvec_slice2()
zaps the names of the result.vec_slice2()
with lists makes use of the list storage requirement and calls.subset2()
.vec_assign2()
with lists wraps the RHS into a list. Genericity is ensured byvec_assign()
which coerces the RHS (now a list) to the type of the LHS (a list type). This allows the class of the LHS to initialise attributes, possibly based on the contents of the RHS.One big difference with
[[<-
is thatNULL
values are not treated as a deletion sentinel.There is currently no way to remove elements:
These operations are unexported for now.