M ChangeLog => ChangeLog +4 -0
@@ 1,3 1,7 @@
+2022-08-31 Enrico Schumann <es@enricoschumann.net>
+
+ * R/functions.R (insert): recycle "what"
+
2022-08-26 Enrico Schumann <es@enricoschumann.net>
* R/repos.R (find_git): add argument 'nchar', to
M DESCRIPTION => DESCRIPTION +1 -1
@@ 2,7 2,7 @@ Package: esutils
Type: Package
Title: esutils
Version: 0.3-0
-Date: 2022-08-26
+Date: 2022-08-31
Maintainer: Enrico Schumann <es@enricoschumann.net>
Authors@R: person(given = "Enrico", family = "Schumann",
role = c("aut", "cre"),
M R/backup.R => R/backup.R +1 -1
@@ 70,7 70,7 @@ flatten <- function(dir, out.dir, pattern = NULL) {
path8.3 <- function(path = ".") {
if (.Platform$OS.type != "windows")
- returns(path)
+ return(path)
old.options <- options(useFancyQuotes = FALSE)
on.exit(options(old.options))
p <- paste(shQuote(path), collapse = " ")
M R/functions.R => R/functions.R +2 -0
@@ 629,6 629,8 @@ insert <- function(x, what, before.index) {
what <- what[ii]
before.index <- before.index[ii]
}
+ if (length(what) < length(before.index))
+ what <- rep(what, length(before.index)/length(what))
before.index <- before.index +
seq(from = 0, to = length(what) - 1)
ans <- vector(class(x), length(x) + length(what))
M inst/tinytest/test_insert.R => inst/tinytest/test_insert.R +7 -0
@@ 4,3 4,10 @@ expect_equal(insert(1:5, 99, 3), c(1:2, 99, 3:5))
expect_equal(insert(1:5, 98:99, c(1,5)), c(98, 1:4, 99, 5))
expect_equal(insert(1:3, 101:103, 1:3), c(101,1,102,2,103,3))
+
+
+expect_equal(insert(letters[1:5], " ", c(2, 4)),
+ c("a", " ", "b", "c", " ", "d", "e"))
+
+expect_equal(insert(letters[1:5], c(" ", "Z"), c(2, 4)),
+ c("a", " ", "b", "c", "Z", "d", "e"))