Closed brooksambrose closed 3 years ago
Hi. The following works:
> R.utils::insert(x=head(letters), ats=c(1, 4), values=list(LETTERS[1:2], LETTERS[3]))
[1] "A" "B" "a" "b" "c" "C" "d" "e" "f"
insert()
could be updated to internally turn:R.utils::insert(x=head(letters), at=c(1,1,4), values=LETTERS[1:3])
into the above automatically using something like:
ats <- c(1,1,4)
values <- LETTERS[1:3]
valuesL <- by(values, INDICES = ats, FUN = identity)
attributes(valuesL) <- NULL
R.utils::insert(x=head(letters), ats=unique(ats), values=valuesL)
While doing this, I also noticed that insert()
is a little bit picky about:
values
being a strict vector, which means I had to do attributes(valuesL) <- NULL
above (fixed in develop, cf. commit f391f1fb)I've added support for what you've tried/expected to the develop
branch (=next release), i.e.
> R.utils::insert(x=head(letters), ats=c(1,1,4), values=LETTERS[1:3])
[1] "A" "B" "a" "b" "c" "C" "d" "e" "f"
I am unable to insert two adjacent items into a series using
R.utils::insert
. Please let me know if this is actually possible using the command as is without post processing, otherwise I would submit that it is a reasonable thing to expect the function to do.Created on 2021-01-23 by the reprex package (v0.3.0)