Add vec_slice2()
and vec_assign2()
#1228
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.