rlist/ 0000755 0001751 0000144 00000000000 12700434260 011423 5 ustar hornik users rlist/tests/ 0000755 0001751 0000144 00000000000 12700425755 012576 5 ustar hornik users rlist/tests/testthat.R 0000644 0001751 0000144 00000000051 12700425755 014555 0 ustar hornik users library(testthat)
test_check("rlist")
rlist/tests/testthat/ 0000755 0001751 0000144 00000000000 12700434260 014425 5 ustar hornik users rlist/tests/testthat/test-internal.R 0000644 0001751 0000144 00000000364 12700425755 017355 0 ustar hornik users context("internal")
test_that("internal", {
e <- list2env(list(a = 1), parent = emptyenv())
expect_error(try_list(expression(symbol1, symbol2), envir = e))
expect_equal(try_list(expression(symbol1, symbol2), 0, envir = e), 0)
})
rlist/tests/testthat/test-utils.R 0000644 0001751 0000144 00000001176 12700425755 016703 0 ustar hornik users context("utils")
test_that("tryGet", {
e <- new.env()
e$x <- 1
expect_identical(tryGet(x, 0, envir = e), e$x)
expect_identical(with(e, tryGet(x, 0)), e$x)
expect_identical(tryGet(y, 0), 0)
expect_error(tryGet(y + 1, 0))
expect_identical(list.map(list(list(a = 1, b = 2), list(a = 1, c = 2)), a + tryGet(b,
0) + tryGet(c, 0)), list(3, 3))
})
test_that("tryEval", {
e <- new.env()
e$x <- 1
expect_identical(with(e, tryEval(x, 0)), e$x)
expect_identical(tryEval(y, 0), 0)
expect_identical(list.map(list(list(a = 1, b = 2), list(a = 1, c = 2)), tryEval(a +
b + c, 0)), list(0, 0))
})
rlist/tests/testthat/test-find.R 0000644 0001751 0000144 00000001764 12700425755 016466 0 ustar hornik users context("find")
test_that("list.findi", {
x <- list(1, 2, c(3, 4))
expect_identical(list.findi(x, any(. >= 2)), 2L)
expect_identical(list.findi(x, any(. >= 2), 2), c(2L, 3L))
expect_identical(list.findi(x, any(. >= 2), 3), c(2L, 3L))
expect_identical(list.findi(x, any(. >= 2), 4), c(2L, 3L))
})
test_that("list.find", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.find(x, type == "B", 1), x[2])
expect_identical(list.find(x, type == "B", 2), x[c(2, 3)])
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_identical(list.find(x, sum(.) >= 4), x[2])
# list of lists
l1 <- list(a = list(x = 1, y = 2), b = list(x = 2, y = 3))
expect_identical(list.find(l1, sum(unlist(.)) <= 4), l1[1])
lapply(2:4, function(i) list.find(l1, sum(unlist(.)) <= i))
})
rlist/tests/testthat/test-group.R 0000644 0001751 0000144 00000004473 12700425755 016702 0 ustar hornik users context("group")
test_that("list.group", {
# simple list
x <- list(a = 1, b = 2, c = 3, d = 2, e = 3, f = 1)
expect_identical(list.group(x, .), list(`1` = list(a = 1, f = 1), `2` = list(b = 2,
d = 2), `3` = list(c = 3, e = 3)))
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.group(x, type), list(A = x["p1"], B = x[c("p2", "p3")]))
expect_identical(list.group(x, mean(unlist(score))), list(`8` = x["p3"], `9` = x[c("p1",
"p2")]))
expect_identical(list.group(1:10, . %% 3, . %% 2), structure(list(`0` = structure(list(`0` = 6L,
`1` = c(3L, 9L)), .Names = c("0", "1")), `1` = structure(list(`0` = c(4L,
10L), `1` = c(1L, 7L)), .Names = c("0", "1")), `2` = structure(list(`0` = c(2L,
8L), `1` = 5L), .Names = c("0", "1"))), .Names = c("0", "1", "2")))
expect_identical(list.group(c(3, 1, 3, 3, 2, 2), letters[.], sorted = FALSE),
list(c = c(3, 3, 3), a = 1, b = c(2, 2)))
expect_identical(list.group(c(3, 1, 3, 3, 2, 2), letters[.], sorted = TRUE),
list(a = 1, b = c(2, 2), c = c(3, 3, 3)))
# test dynamic scoping
lapply(2:4, function(i) list.group(x, sum(unlist(score)) <= i))
})
test_that("list.ungroup", {
xg <- list(`1` = list(a = 1, f = 1), `2` = list(b = 2, d = 2), `3` = list(c = 3,
e = 3))
xg2 <- list(a = list(a = 1, f = 1), c = list(b = 2, d = 2), b = list(c = 3, e = 3))
expect_identical(list.ungroup(xg, sort.names = TRUE), list(a = 1, b = 2, c = 3,
d = 2, e = 3, f = 1))
expect_identical(list.ungroup(xg2, sort.names = FALSE), list(a = 1, f = 1, b = 2,
d = 2, c = 3, e = 3))
x <- list(a = list(a1 = list(x=list(x1=2,x2=3),y=list(y1=1,y2=3)), a0 = list(x=list(x1=1,x2=5),y=list(y1=0,y2=1))),
b = list(b1 = list(x=list(x1=2,x2=6),y=list(y1=3,y2=2))))
expect_identical(list.ungroup(x, level = 1L), c(x$a, x$b))
expect_identical(list.ungroup(x, level = 2L), c(unlist(unname(x$a), recursive = FALSE), unlist(unname(x$b), recursive = FALSE)))
expect_identical(list.ungroup(x, level = 1L, group.names = TRUE), unlist(x, recursive = FALSE))
expect_identical(list.ungroup(x, level = 2L, group.names = TRUE), c(unlist(unlist(x, recursive = FALSE), recursive = FALSE)))
})
rlist/tests/testthat/test-io.R 0000644 0001751 0000144 00000003575 12700425755 016157 0 ustar hornik users context("io")
test_that("list.serialize", {
x <- list(a = 1, b = 2, c = 3, d = list(x = 1, y = 2))
f <- tempfile(fileext = ".json")
expect_identical(list.serialize(x, f), x)
expect_identical(list.unserialize(f), x)
file.remove(f)
f <- tempfile()
expect_identical(list.serialize(x, f), x)
expect_identical(list.unserialize(f), x)
file.remove(f)
})
test_that("list.save, list.load", {
x <- list(a = 1, b = 2, c = 3, d = list(x = 1, y = c(1, 2, 3)))
f <- tempfile(fileext = ".json")
expect_equal(list.save(x, file = f), x)
expect_equal(list.load(f), x)
file.remove(f)
f <- tempfile(fileext = ".yaml")
expect_equal(list.save(x, file = f), x)
expect_equal(list.load(f), x)
file.remove(f)
f <- tempfile(fileext = ".rds")
expect_equal(list.save(x, file = f), x)
expect_equal(list.load(f), x)
file.remove(f)
f <- tempfile(fileext = ".rdata")
expect_equal(list.save(x, file = f), x)
expect_equal(list.load(f), x)
file.remove(f)
f <- tempfile(fileext = ".xml")
writeLines("1", f)
expect_equal(list.load(f), list(a = "1"))
file.remove(f)
# guess
f <- tempfile()
expect_equal(list.save(x, file = f, type = "yaml"), x)
expect_equal(list.load(f), x)
file.remove(f)
f <- tempfile()
expect_error(list.save(x, file = f, type = "unsupported_file_type"))
f <- tempfile()
expect_error(list.load(f, "unsupported_file_type"))
n <- 3
fs <- vapply(seq_len(n), function(i) tempfile(fileext = ".json"), character(1L))
ds <- lapply(seq_len(n), function(i) list(a = i, b = i + 1L))
Map(function(d, f) {
list.save(d, f)
}, ds, fs)
expect_equal(unname(list.load(fs)), ds)
expect_equal(list.load(fs, action = "ungroup"), list.ungroup(lapply(fs, list.load)))
expect_equal(list.load(fs, action = "merge"), do.call("list.merge", ds))
file.remove(fs)
})
rlist/tests/testthat/test-join.R 0000644 0001751 0000144 00000001360 12700425755 016475 0 ustar hornik users context("join")
test_that("list.join", {
l1 <- list(p1 = list(name = "Ken", age = 20), p2 = list(name = "James", age = 21),
p3 = list(name = "Jenny", age = 20))
l2 <- list(p1 = list(name = "Jenny", age = 20, type = "A"), p2 = list(name = "Ken",
age = 20, type = "B"), p3 = list(name = "James", age = 21, type = "A"))
l3 <- list(p1 = list(name = "Ken", age = 20, type = "B"), p2 = list(name = "James",
age = 21, type = "A"), p3 = list(name = "Jenny", age = 20, type = "A"))
expect_identical(list.join(l1, l2, name), l3)
expect_identical(list.join(l1, l2, .[c("name", "age")]), l3)
expect_identical(list.join(l1, l2, .[c("name", "age")], .[c("name", "age")]),
l3)
expect_error(list.join(l1, l2, name, age))
})
rlist/tests/testthat/test-subset.R 0000644 0001751 0000144 00000003703 12700425755 017046 0 ustar hornik users context("subset")
test_that("subset.list", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(subset(x, type == "B"), x[c(2, 3)])
expect_identical(subset(x, type == "B", score$c1), list(p2 = 9, p3 = 9))
expect_identical(subset(x, type == "B", item ~ item$score$c2), list(p2 = 9, p3 = 7))
# scoping
lapply(1:3, function(i) subset(x, score$c2 >= 7 + i, score$c1 + i))
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_identical(subset(x, .["x"] >= 2, .["y"]), list(b = c(y = 4)))
expect_identical(subset(x, sum(.) <= 4, max(.)), list(a = 2))
# list of lists
l1 <- list(a = list(x = 1, y = 2), b = list(x = 2, y = 3))
expect_identical(subset(l1, sum(unlist(.)) <= 4, unlist(.)), list(a = c(x = 1,
y = 2)))
# list of objects of list mode
l2 <- lapply(1:10, function(i) {
x <- rnorm(100)
y <- 2 * x + rnorm(100) * 0.2
lm(y ~ x)
})
expect_identical(subset(l2, mean(residuals) >= 0, mean(residuals^2)), {
lst <- lapply(l2, function(item) {
if (mean(item$residuals) >= 0) {
mean(item$residuals^2)
}
})
lst[vapply(lst, is.null, logical(1))] <- NULL
lst
})
expect_identical(subset(l2, mean(.$residuals) >= 0, mean(.$residuals^2)), {
lst <- lapply(l2, function(item) {
if (mean(item$residuals) >= 0) {
mean(item$residuals^2)
}
})
lst[vapply(lst, is.null, logical(1))] <- NULL
lst
})
expect_identical(subset(l2, mean(resid(.)) >= 0, mean(resid(.)^2)), {
lst <- lapply(l2, function(item) {
if (mean(item$residuals) >= 0) {
mean(item$residuals^2)
}
})
lst[vapply(lst, is.null, logical(1))] <- NULL
lst
})
# list of S4 objects
# list of other objects
})
rlist/tests/testthat/test-sort.R 0000644 0001751 0000144 00000003444 12700425755 016532 0 ustar hornik users context("sort")
test_that("list.sort", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.sort(x, type, (score$c2)), x[c(1, 2, 3)])
expect_identical(list.sort(x, min(score$c1, score$c2)), x[c(3, 1, 2)])
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_identical(list.sort(x, sum(.)), x[c(1, 2)])
expect_identical(list.sort(x, (sum(.))), x[c(2, 1)])
expect_identical(list.sort(c("a", "b", "c")), c("a", "b", "c"))
expect_identical(list.sort(c("a", "b", "c"), (.)), c("c", "b", "a"))
expect_identical(list.sort(list("a", "b", "c"), .), list("a", "b", "c"))
expect_identical(list.sort(list("a", "b", "c"), (.)), list("c", "b", "a"))
# warning in irregular cases
expect_warning(list.sort(list(1, 2, c(2, 3)), .), "^Non-single value in column")
expect_warning(list.sort(list(1, 2, "a"), .), "^Inconsistent classes")
lapply(1:3, function(i) list.sort(x, sum(.) + i))
})
test_that("list.order", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.order(x, type, (score$c2)), c(1, 2, 3))
expect_equal(list.order(x, min(score$c1, score$c2)), c(3, 1, 2))
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_equal(lapply(1:3, function(i) list.order(x, sum(.) + i)), list(c(1, 2),
c(1, 2), c(1, 2)))
# warning in irregular cases
expect_warning(list.order(list(1, 2, c(2, 3)), .), "^Non-single value in column")
expect_warning(list.order(list(1, 2, "a"), .), "^Inconsistent classes")
})
rlist/tests/testthat/test-select.R 0000644 0001751 0000144 00000001371 12700425755 017017 0 ustar hornik users context("select")
test_that("list.select", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.select(x, type), lapply(x, function(xi) {
xi["type"]
}))
expect_identical(list.select(x, type, score), lapply(x, function(xi) {
xi[c("type", "score")]
}))
expect_identical(list.select(x, range = range(unlist(score))), lapply(x, function(xi) {
list(range = range(unlist(xi$score)))
}))
expect_identical(list.select(x, n = length(.)), lapply(x, function(xi) {
list(n = length(xi))
}))
lapply(1:3, function(i) list.select(x, p = score$c1 + i))
})
rlist/tests/testthat/test-filter.R 0000644 0001751 0000144 00000002334 12700425755 017025 0 ustar hornik users context("filter")
test_that("list.is", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.is(x, type == "B"), unlist(lapply(x, function(item) item$type ==
"B")))
l1 <- list(a = list(x = 1, y = 2), b = list(x = 2, y = 3))
expect_identical(lapply(2:4, function(i) list.is(l1, sum(unlist(.)) <= i)),
list(c(a = FALSE, b = FALSE), c(a = TRUE, b = FALSE), c(a = TRUE, b = FALSE)))
})
test_that("list.filter", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.filter(x, type == "B"), x[c(2, 3)])
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_identical(list.filter(x, sum(.) >= 4), x["b"])
# list of lists
l1 <- list(a = list(x = 1, y = 2), b = list(x = 2, y = 3))
expect_identical(list.filter(l1, sum(unlist(.)) <= 4), l1["a"])
# test dynamic scoping
lapply(2:4, function(i) list.filter(l1, sum(unlist(.)) <= i))
})
rlist/tests/testthat/test-basic.R 0000644 0001751 0000144 00000035656 12700425755 016636 0 ustar hornik users context("basic")
test_that("list.append", {
# atomic vector
expect_identical(list.append(c(1, 2, 3), 4, 5), c(1, 2, 3, 4, 5))
expect_identical(list.append(c(a = 1, b = 2), c = 3), c(a = 1, b = 2, c = 3))
# simple list
x <- list(a = 1, b = 2)
expect_identical(list.append(x, c = 3), c(x, c = 3))
expect_identical(lapply(1:2, function(i) list.append(x, d = i)), lapply(1:2,
function(i) c(x, d = i)))
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
p4 <- list(type = "A", score = list(c1 = 10, ce = 6))
expect_identical(list.append(x, p4 = p4), c(x, p4 = list(p4)))
})
test_that("list.prepend", {
# atomic vector
expect_identical(list.prepend(c(1, 2, 3), 4, 5), c(4, 5, 1, 2, 3))
expect_identical(list.prepend(c(a = 1, b = 2), c = 3), c(c = 3, a = 1, b = 2))
# simple list
x <- list(a = 1, b = 2)
expect_identical(list.prepend(x, c = 3), c(c = 3, x))
expect_identical(lapply(1:2, function(i) list.prepend(x, d = i)), lapply(1:2,
function(i) c(list(d = i), x)))
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
p0 <- list(type = "A", score = list(c1 = 10, ce = 6))
expect_identical(list.prepend(x, p0 = p0), c(p0 = list(p0), x))
})
test_that("list.insert", {
expect_identical(list.insert(c(1, 2, 3), 2, 0), c(1, 0, 2, 3))
x <- list(a = 1, b = 2, c = 3)
expect_identical(list.insert(x, 2, q = 0), list(a = 1, q = 0, b = 2, c = 3))
expect_identical(lapply(1:2, function(i) list.insert(x, 2, q = i)), lapply(1:2,
function(i) list(a = 1, q = i, b = 2, c = 3)))
})
test_that("list.extract", {
# simple list
x <- list(a = 1, b = 2, c = 3)
expect_identical(list.extract(x, 1), x[[1]])
expect_identical(list.extract(x, "a"), x[["a"]])
expect_identical(lapply(1:2, function(i) list.extract(x, i)), lapply(1:2, function(i) x[[i]]))
})
test_that("list.subset", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.subset(x, c("p1", "p2")), x[c("p1", "p2")])
expect_identical(list.subset(x, grepl("^p", names(x))), x[])
})
test_that("list.count", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.count(x, type == "B"), 2)
expect_equal(list.count(x, score$c1 < 10), 2)
expect_equal(lapply(c(8, 9, 10), function(i) list.count(x, score$c1 <= i)), list(0,
2, 3))
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_equal(list.count(x, sum(.) >= 3), 2)
expect_equal(list.count(x, mean(.) >= 3), 1)
})
test_that("list.reverse", {
# simple list
x <- list(a = 1, b = 2, c = 3)
expect_identical(list.reverse(x), x[c(3, 2, 1)])
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.reverse(x), x[c(3, 2, 1)])
})
test_that("list.merge", {
# simple list
x <- list(a = 1, b = 2, c = list(x = 1, y = 2))
expect_identical(list.merge(x, list(b = 5)), list(a = 1, b = 5, c = list(x = 1,
y = 2)))
expect_identical(list.merge(x, list(c = list(z = 3))), list(a = 1, b = 2, c = list(x = 1,
y = 2, z = 3)))
# multiple lists
l1 <- list(a = 1, b = list(x = 1, y = 1))
l2 <- list(a = 2, b = list(z = 2))
l3 <- list(a = 2, b = list(x = 3))
expect_identical(list.merge(l1, l2, l3), modifyList(modifyList(l1, l2), l3))
})
test_that("list.do", {
expect_equal(list.do(list(1, 2, 3), sum), sum(1:3))
expect_equal(list.do(list(1, 2, 3), "sum"), sum(1:3))
})
test_that("list.apply", {
expect_identical(list.apply(c(1, 2, 3), "+", 1), list(2, 3, 4))
expect_identical(list.apply(c(1, 2, 3), `+`, 1), list(2, 3, 4))
})
test_that("list.rbind", {
x <- lapply(1:10, function(i) c(a = i, b = i^2))
expect_identical(list.rbind(x), do.call(rbind, x))
})
test_that("list.cbind", {
x <- list(data.frame(a = rnorm(10), b = rnorm(10)), data.frame(c = rnorm(10),
d = rnorm(10)), data.frame(e = rnorm(10), f = rnorm(10)))
expect_identical(list.cbind(x), do.call(cbind, x))
})
test_that("list.stack", {
x <- lapply(1:10, function(i) list(a = i, b = i^2))
expect_false(is.null(list.stack(x)))
x <- lapply(1:10, function(i) list(a = c(i, i + 1), b = c(i^2, i^2 + 1)))
expect_false(is.null(list.stack(x)))
})
test_that("list.match", {
# simple list
x <- list(a = 1, b = 2)
expect_identical(list.match(x, "a"), x["a"])
expect_identical(list.match(x, "[ab]"), x)
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.match(x, "p[12]"), x[c("p1", "p2")])
})
test_that("list.take, list.skip", {
# simple list
x <- list(a = 1, b = 2)
expect_identical(list.take(x, 1), x[1])
expect_identical(list.take(x, 0), x[0])
expect_identical(list.take(x, -1), x[-1])
expect_identical(list.skip(x, 1), x[2])
expect_identical(list.skip(x, 0), x)
expect_identical(list.skip(x, -1), x[1])
})
test_that("list.takeWhile, list.skipWhile", {
# simple list
x <- list(a = 1, b = 2)
expect_identical(list.takeWhile(x, . <= 1), x[1])
expect_equal(length(list.takeWhile(x, . >= 3)), 0)
lapply(1:3, function(i) list.takeWhile(x, . <= i))
expect_error(list.takeWhile(x, . >= p))
expect_identical(list.skipWhile(x, . <= 1), x[2])
expect_equal(length(list.skipWhile(x, . >= 3)), 0)
lapply(1:3, function(i) list.skipWhile(x, . <= i))
expect_error(list.skipWhile(x, . >= p))
})
test_that("list.remove", {
x <- list(a = 1, b = 2)
expect_identical(list.remove(x, c(FALSE, TRUE)), x[1])
expect_identical(list.remove(x, 1), x[2])
expect_identical(list.remove(x, "b"), x["a"])
expect_identical(list.remove(x, c("a", "b")), x[0])
})
test_that("list.exclude", {
x <- list(a = 1, b = 2)
expect_identical(list.exclude(x, . >= 2), x[1])
})
test_that("list.sample", {
x <- list(a = 1, b = 2, c = 3)
expect_equal(length(list.sample(x, 2, weight = .)), 2)
lapply(1:2, function(n) list.sample(x, n))
})
test_that("list.cases", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.cases(x, type, sort = T), c("A", "B"))
expect_equal(list.cases(x, mean(unlist(score))), c(8, 9))
expect_equal(lapply(c("A", "B"), function(i) list.cases(x, type == i)),
list(c(FALSE, TRUE), c(FALSE, TRUE)))
x <- list(x = LETTERS[1:3], y = LETTERS[3:5])
expect_equal(list.cases(x), Reduce(union, x))
})
test_that("list.common", {
x <- list(c("a", "b", "c"), c("a", "b"), c("b", "c"))
expect_equal(list.common(x, .), c("b"))
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.common(x, names(.)), c("type", "score"))
expect_equal(list.common(x, names(score)), c("c1", "c2"))
x <- list(x = LETTERS[1:3], y = LETTERS[3:5])
expect_equal(list.common(x), Reduce(intersect, x))
})
test_that("list.all", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.all(x, type == "B"), FALSE)
expect_equal(list.all(x, mean(unlist(score)) >= 6), TRUE)
expect_equal(sapply(8:10, function(i) list.all(x, score$c1 >= i)), c(TRUE, TRUE, FALSE))
expect_equal(list.all(logical()), all())
expect_equal(list.all(logical(), na.rm = TRUE), all(na.rm = TRUE))
expect_equal(list.all(c(TRUE, NA, TRUE)), all(c(TRUE, NA, TRUE)))
expect_equal(list.all(c(TRUE, NA, FALSE)), all(c(TRUE, NA, FALSE)))
expect_equal(list.all(c(TRUE, NA, TRUE), na.rm = TRUE), all(c(TRUE, NA, TRUE),
na.rm = TRUE))
expect_equal(list.all(c(TRUE, NA, FALSE), na.rm = TRUE), all(c(TRUE, NA, FALSE),
na.rm = TRUE))
expect_equal(list.all(list(c(1,2,3),c(2,3,4)), . <= 3, na.rm = FALSE), NA)
expect_equal(list.all(list(1,-2,10), x ~ x > 0), FALSE)
expect_equal(list.all(list(1,-2,10), x ~ x + 10 > 0), TRUE)
expect_error(list.all(list(1,2,3), . > p))
})
test_that("list.any", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.any(x, type == "B"), TRUE)
expect_equal(list.any(x, mean(unlist(score)) >= 20), FALSE)
expect_equal(sapply(8:10, function(i) list.any(x, score$c1 >= i)), c(T, T, T))
expect_equal(list.any(logical()), any())
expect_equal(list.any(logical(), na.rm = TRUE), any(na.rm = TRUE))
expect_equal(list.any(c(TRUE, NA, TRUE)), any(c(TRUE, NA, TRUE)))
expect_equal(list.any(c(TRUE, NA, FALSE)), any(c(TRUE, NA, FALSE)))
expect_equal(list.any(c(TRUE, NA, TRUE), na.rm = TRUE), any(c(TRUE, NA, TRUE),
na.rm = TRUE))
expect_equal(list.any(c(TRUE, NA, FALSE), na.rm = TRUE), any(c(TRUE, NA, FALSE),
na.rm = TRUE))
expect_equal(list.any(list(1,-2,10), x ~ x > 0), TRUE)
expect_equal(list.any(list(1,-2,10), x ~ x - 10 > 0), FALSE)
expect_error(list.any(list(1,2,3), . > p))
})
test_that("list.first", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.first(x, type == "B"), x[[2L]])
expect_equal(list.first(x, unlist(score$c1 <= 9)), x[[2L]])
expect_identical(list.first(x, score$c1 < 9 || score$c3 >= 5), NULL)
expect_equal(list.first(c(NA, NA, 1), . <= 1), 1)
expect_error(list.first(list(1,2,3), . > p))
})
test_that("list.last", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.last(x, type == "B"), x[[3L]])
expect_equal(list.last(x, unlist(score$c1 <= 9)), x[[3L]])
expect_identical(list.last(x, score$c1 < 9 || score$c3 >= 5), NULL)
expect_error(list.last(list(1,2,3), . > p))
})
test_that("list.table", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
x.types <- c("A", "B", "B")
x.c1 <- c(10, 9, 9)
expect_identical(list.table(x, type), table(type = x.types))
expect_identical(list.table(x, type, c1 = score$c1), table(type = x.types, c1 = x.c1))
x <- list(list(a = 1, b = NULL), list(a = 2, b = 1), list(a = 3, b = 1))
expect_identical(as.integer(list.table(x, a, b)), c(0L, 1L, 1L, 1L, 0L, 0L))
})
test_that("list.zip", {
a <- list(1, 2)
b <- list("a", "b")
expect_identical(list.zip(a, b), list(list(a = 1, b = "a"), list(a = 2, b = "b")))
})
test_that("list.unzip", {
x <- list(p1 = list(a = 1, b = 5), p2 = list(a = 2, b = 3))
x1 <- list(p1 = list(a = 1, b = 5), p2 = list(a = 2, b = 3, c = 4))
expect_identical(list.unzip(x), list(a = c(p1 = 1, p2 = 2), b = c(p1 = 5, p2 = 3)))
expect_identical(list.unzip(x1, .fields = "union"), list(a = c(p1 = 1, p2 = 2),
b = c(p1 = 5, p2 = 3), c = c(p1 = NA, p2 = 4)))
expect_identical(list.unzip(x, a = "identity"), list(a = list(p1 = 1, p2 = 2),
b = c(p1 = 5, p2 = 3)))
expect_identical(list.unzip(x, a = NULL), list(b = c(p1 = 5, p2 = 3)))
})
test_that("list.flatten", {
p <- list(a = 1, b = list(b1 = 2, b2 = 3), c = list(c1 = list(c11 = "a", c12 = "x"),
c2 = 3))
q <- list(a = c(1, 2, 3), b = list(x = 1, y = list(z = 1, z2 = 2)))
expect_identical(list.flatten(p), list(a = 1, b.b1 = 2, b.b2 = 3, c.c1.c11 = "a",
c.c1.c12 = "x", c.c2 = 3))
expect_identical(list.flatten(q), list(a = c(1, 2, 3), b.x = 1, b.y.z = 1, b.y.z2 = 2))
p <- list(a=1,b=list(x="a",y="b",z=10))
expect_identical(list.flatten(p), list(a=1, b.x = "a", b.y = "b", b.z = 10))
expect_identical(list.flatten(p, classes = "numeric"), list(a = 1, b.z = 10))
expect_identical(list.flatten(p, classes = "character"), list(b.x = "a", b.y = "b"))
expect_identical(list.flatten(p, classes = "integer"), list())
expect_identical(list.flatten(p, use.names = FALSE), list(1, "a", "b", 10))
})
test_that("list.names", {
expect_identical(list.names(list(a = 1, b = 2)), c("a", "b"))
expect_identical(list.names(list(1, 2)), NULL)
expect_identical(list.names(list(1, 2), letters[.]), list(a = 1, b = 2))
expect_identical(list.names(list(a = 1, b = 2), NULL), list(1, 2))
})
test_that("list.parse", {
expect_identical(list.parse(c(a = 1)), list(a = 1))
expect_identical({
mat <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 3)
rownames(mat) <- c("a", "b", "c")
colnames(mat) <- paste0("V", 1:2)
list.parse(mat)
}, list(a = list(V1 = 1, V2 = 4), b = list(V1 = 2, V2 = 5), c = list(V1 = 3,
V2 = 6)))
expect_identical(list.parse("hello"), list("hello"))
expect_identical(list.parse(data.frame(x = c(1, 2), y = c(2, 3))), list(`1` = list(x = 1,
y = 2), `2` = list(x = 2, y = 3)))
expect_equal(list.parse("a: 1", "yaml"), list(a = 1))
expect_equal(list.parse("{ \"a\": 1, \"b\": 2 }", "json"), list(a = 1, b = 2))
expect_equal(list.parse("12", "xml"), list(a = "1",
b = "2"))
expect_error(list.parse("a:1,b:2", "js"), "Unsupported type of data")
expect_equal(list.parse(c("a: 1", "{ \"a\": 1, \"b\": 2 }"), c("yaml", "json")),
list(list(a = 1), list(a = 1, b = 2)))
})
test_that("list.clean", {
expect_identical(list.clean(list(1, 2, NULL)), list(1, 2))
expect_identical(list.clean(list(1, 2, NA), is.na), list(1, 2))
expect_identical(list.clean(list(1, 2, numeric(), list(1, 2, NULL)), function(x) length(x) ==
0L, recursive = TRUE), list(1, 2, list(1, 2)))
expect_identical(list.clean(list(1, 2, list(1, 2, NULL), NULL), recursive = TRUE),
list(1, 2, list(1, 2)))
})
test_that("list.which", {
x <- c(1, 2, 3)
expect_identical(list.which(x, . >= 2), which(x >= 2))
})
test_that("list.expand", {
expect_identical(list.expand(), list())
expect_identical(list.expand(x = integer()), list())
expect_identical(list.expand(x = 1:3, y = integer()), list())
expect_identical(list.expand(x = c(1,2), y = c(2,3)),
list(list(x = 1, y = 2), list(x = 2, y = 2),
list(x = 1, y = 3), list(x = 2, y = 3)))
})
rlist/tests/testthat/test-search.R 0000644 0001751 0000144 00000005577 12700425755 017021 0 ustar hornik users context("search")
test_that("list.search", {
# logical search
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.search(x, identical(., "A")), list(p1.type = "A"))
expect_identical(list.search(x, identical(., "A"), unlist = TRUE), c(p1.type = "A"))
expect_identical(list.search(x, identical(., 9)), list(p2.score.c1 = 9, p2.score.c2 = 9,
p3.score.c1 = 9))
x <- list(p1 = list(x = c("A", "B", "C"), y = list(y1 = "A", y2 = c("B", "C"))),
p2 = list(a = c("A", "B"), b = list(b1 = c("B", "C"), b2 = list("C", "B"))))
expect_identical(list.search(x, all(. == "A")), list(p1.y.y1 = "A"))
expect_identical(list.search(x, any("A" %in% .)), list(p1.x = c("A", "B", "C"),
p1.y.y1 = "A", p2.a = c("A", "B")))
# fuzzy search
x <- list(p1 = list(name = "Ken", age = 24), p2 = list(name = "Kent", age = 26),
p3 = list(name = "Sam", age = 24), p4 = list(name = "Keynes", age = 30),
p5 = list(name = "Kwen", age = 31))
expect_equal(list.search(x, grepl("^K\\w+[ts]", .), "character", unlist = TRUE),
c(p2.name = "Kent", p4.name = "Keynes"))
expect_equal(list.search(x, any(stringdist::stringdist(., "Ken") <= 1), "character",
unlist = TRUE), c(p1.name = "Ken", p2.name = "Kent", p5.name = "Kwen"))
expect_identical(list.search(x, all(stringdist::stringdist(., "Ken") == 0), "character"),
list(p1.name = "Ken"))
x <- list(p1 = list(name = c("Ken", "Ren"), age = 24), p2 = list(name = c("Kent",
"Potter"), age = 26), p3 = list(name = c("Sam", "Lee"), age = 24), p4 = list(name = c("Keynes",
"Bond"), age = 30), p5 = list(name = c("Kwen", "Hu"), age = 31))
expect_equal(list.search(x, all(stringdist::stringdist(., "Ken") <= 1), "character"),
list(p1.name = c("Ken", "Ren")))
expect_equal(list.search(x, any(stringdist::stringdist(., "Ken") <= 1), "character"),
list(p1.name = c("Ken", "Ren"), p2.name = c("Kent", "Potter"), p5.name = c("Kwen",
"Hu")))
expect_equal(list.search(x, !any(stringdist::stringdist(., "Ken") <= 1), "character"),
list(p3.name = c("Sam", "Lee"), p4.name = c("Keynes", "Bond")))
y <- list(n = 1:10, list(df = data.frame(id = 1:10, letter = letters[1:10], stringsAsFactors = F)),
list("aa", "bb"))
expect_identical(list.search(y, .[grepl("a", .)], "character"), list(df.letter = "a",
"aa"))
expect_error(list.search(y, . <= p))
})
test_that("counting", {
x <- list(p1 = list(name = "Ken", age = 24), p2 = list(name = "Kent", age = 26),
p3 = list(name = "Sam", age = 24), p4 = list(name = "Keynes", age = 30),
p5 = list(name = "Kwen", age = 31))
expect_equal(list.search(x, n ~ n >= 25, "numeric", n = 2, unlist = TRUE), c(p2.age = 26,
p4.age = 30))
expect_error(list.search(x, . <= p))
})
rlist/tests/testthat/test-update.R 0000644 0001751 0000144 00000001536 12700425755 017025 0 ustar hornik users context("update")
test_that("list.update", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.update(x, type = NULL), lapply(x, function(xi) {
xi[-1]
}))
expect_identical(list.update(x, score = list(min = min(unlist(score)))), lapply(x,
function(xi) {
modifyList(xi, list(score = list(min = min(unlist(xi$score)))))
}))
expect_identical(list.update(x, range = range(unlist(score))), lapply(x, function(xi) {
modifyList(xi, list(range = range(unlist(xi$score))))
}))
expect_identical(list.update(x, n = length(.)), lapply(x, function(xi) {
modifyList(xi, list(n = length(xi)))
}))
lapply(1:3, function(i) list.update(x, c = i))
})
rlist/tests/testthat/test-List.R 0000644 0001751 0000144 00000005662 12700425755 016462 0 ustar hornik users context("List")
test_that("List", {
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical({
List(x)$group(type)$map(g ~ List(g)$map(score)$call(unlist)$call(mean)$data)$data
}, list(A = 9, B = 8.5))
expect_identical({
local({
i <- 3
List(1:3)$map(x ~ x + i)[]
})
}, list(4, 5, 6))
expect_identical({
local({
i <- 1
List(1:3)$map(x ~ x + i)$filter(x ~ x <= 1 + i)[]
})
}, list(2))
expect_identical(List(1:3)$all(. >= 0)[], TRUE)
expect_identical(List(1:3)$any(. <= 5)[], TRUE)
expect_identical(List(x)$cases(type)[], c("A", "B"))
expect_identical(List(x)$class(type)[], list.class(x, type))
expect_identical(List(x)$common(names(score))[], c("c1", "c2"))
expect_identical(List(x)$count(type == "B")[], 2L)
expect_identical(List(x)$filter(type == "B")[], list.filter(x, type == "B"))
expect_identical(List(1:10)$find(.%%2 == 0, 3)[], c(2L, 4L, 6L))
expect_identical(List(1:10)$findi(.%%2 == 0, 3)[], c(2L, 4L, 6L))
expect_identical(List(1:10)$group(.%%3)[], list.group(1:10, .%%3))
expect_identical(List(list(1:10, 2:15))$search(any(. >= 11))[], list.search(list(1:10,
2:15), any(. >= 11)))
expect_identical(local({
i <- 12
List(list(1:10, 2:15))$search(any(. >= i))[]
}), list.search(list(1:10, 2:15), any(. >= 12)))
expect_identical(List(1:200)$table(.%%2, .%%3)[], list.table(1:200, .%%2, .%%3))
expect_identical(List(x)$update(mean = mean(unlist(score)))[], list.update(x,
mean = mean(unlist(score))))
expect_equal(List(c(1, 2, 3)) == c(1, 2, 3), c(TRUE, TRUE, TRUE))
expect_equal(subset(List(1:10), c(TRUE, FALSE)), subset(1:10, c(TRUE, FALSE)))
})
test_that("closure", {
expect_is(List_get_function(quote(`[`)), "function")
expect_is(List_set_function(quote(`[`)), "function")
})
test_that("subsetting", {
expect_identical(List(list(a = 1, b = 2))["a"]$data, list(a = 1))
expect_equal(List(c(a = 1, b = 2))["a"]$data, c(a = 1))
})
test_that("extracting", {
expect_equal(List(list(a = 1, b = 2))[["a"]]$data, 1)
expect_equal(List(list2env(list(a = 1, b = 2)))[["a"]]$data, 1)
})
test_that("assignment", {
expect_identical({
z <- List(list(a = 1, b = 2))
z$a <- 2
z$b <- NULL
z$data
}, list(a = 2))
expect_equal({
z <- new.env()
env <- List(z)
env$a <- 1
env$data$a
}, 1)
expect_identical({
z <- List(c(a = 1, b = 2))
z["a"] <- 2
z$data
}, c(a = 2, b = 2))
expect_identical({
z <- List(c(a = 1, b = 2))
z[["a"]] <- 2
z$data
}, c(a = 2, b = 2))
})
test_that("printing", {
expect_output(print(List(list(1, 2, 3))), "\\$data : list.+")
expect_output(str(List(list(1, 2, 3))), "\\$data : List of 3.+")
expect_output(print(summary(List(rnorm(100)))), "Min.+")
})
rlist/tests/testthat/test-map.R 0000644 0001751 0000144 00000003607 12700425755 016321 0 ustar hornik users context("map")
test_that("list.map", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.map(x, score$c1), list(p1 = 10, p2 = 9, p3 = 9))
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_identical(list.map(x, sum(.)), list(a = 3, b = 7))
lapply(1:3, function(i) list.map(x, sum(.) + i))
})
test_that("list.mapv", {
# simple list
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_equal(list.mapv(x, score$c1), c(p1 = 10, p2 = 9, p3 = 9))
expect_equal(list.mapv(x, x ~ sum(unlist(x$score))), c(p1 = 18, p2 = 18, p3 = 16))
expect_identical(list.mapv(x, score$c1, "integer"), c(p1 = 10L, p2 = 9L, p3 = 9L))
expect_identical(list.mapv(x, score$c1, "integer", use.names = FALSE), c(10L,
9L, 9L))
# list of vectors
x <- list(a = c(x = 1, y = 2), b = c(x = 3, y = 4))
expect_equal(list.mapv(x, sum(.)), c(a = 3, b = 7))
lapply(1:3, function(i) list.mapv(x, sum(.) + i))
})
test_that("list.iter", {
l1 <- list(1, 2, 3)
expect_output(list.iter(l1, cat(.)), "123")
expect_equal(list.iter(l1, {
}), l1)
})
test_that("list.maps", {
l1 <- list(p1 = list(x = 1, y = 2), p2 = list(x = 3, y = 4), p3 = list(x = 1,
y = 3))
l2 <- list(2, 3, 5)
expect_equal(list.maps(a$x * b + a$y, a = l1, b = l2), list(p1 = 4, p2 = 13,
p3 = 8))
expect_equal(list.maps(..1$x * ..2 + ..1$y, l1, l2), list(p1 = 4, p2 = 13, p3 = 8))
expect_equal(list.maps(a * b, a = list(1, 2, 3), b = list(2, 3, 4)), list(2,
6, 12))
expect_equal(list.maps(..1 * ..2, list(1, 2, 3), list(2, 3, 4)), list(2, 6, 12))
})
rlist/tests/testthat/test-class.R 0000644 0001751 0000144 00000001161 12700425755 016642 0 ustar hornik users context("class")
test_that("list.class", {
# simple list
x <- list(a = 1, b = 2, c = 3, d = 2, e = 3, f = 1)
expect_identical(list.class(x, .), list(`1` = list(a = 1, f = 1), `2` = list(b = 2,
d = 2), `3` = list(c = 3, e = 3)))
x <- list(p1 = list(type = "A", score = list(c1 = 10, c2 = 8)), p2 = list(type = "B",
score = list(c1 = 9, c2 = 9)), p3 = list(type = "B", score = list(c1 = 9,
c2 = 7)))
expect_identical(list.class(x, unlist(score)), list(`7` = x["p3"], `8` = x["p1"],
`9` = x[c("p2", "p3")], `10` = x["p1"]))
lapply(8:10, function(i) list.class(x, score$c1 > i))
})
rlist/NAMESPACE 0000644 0001751 0000144 00000003365 12700425755 012662 0 ustar hornik users # Generated by roxygen2: do not edit by hand
S3method("$<-",List)
S3method("==",List)
S3method("[",List)
S3method("[<-",List)
S3method("[[",List)
S3method("[[<-",List)
S3method(list.parse,character)
S3method(list.parse,data.frame)
S3method(list.parse,default)
S3method(list.parse,matrix)
S3method(print,List)
S3method(str,List)
S3method(subset,List)
S3method(subset,list)
S3method(summary,List)
export(List)
export(list.all)
export(list.any)
export(list.append)
export(list.apply)
export(list.cases)
export(list.cbind)
export(list.class)
export(list.clean)
export(list.common)
export(list.count)
export(list.do)
export(list.exclude)
export(list.expand)
export(list.extract)
export(list.filter)
export(list.find)
export(list.findi)
export(list.first)
export(list.flatten)
export(list.group)
export(list.if)
export(list.insert)
export(list.is)
export(list.iter)
export(list.join)
export(list.last)
export(list.load)
export(list.map)
export(list.maps)
export(list.mapv)
export(list.match)
export(list.merge)
export(list.names)
export(list.order)
export(list.parse)
export(list.prepend)
export(list.rbind)
export(list.remove)
export(list.reverse)
export(list.sample)
export(list.save)
export(list.search)
export(list.select)
export(list.serialize)
export(list.skip)
export(list.skipWhile)
export(list.sort)
export(list.stack)
export(list.subset)
export(list.table)
export(list.take)
export(list.takeWhile)
export(list.ungroup)
export(list.unserialize)
export(list.unzip)
export(list.update)
export(list.which)
export(list.zip)
export(tryEval)
export(tryGet)
importFrom(data.table,rbindlist)
importFrom(stats,na.omit)
importFrom(utils,modifyList)
importFrom(utils,str)
importFrom(utils,txtProgressBar)
rlist/NEWS 0000644 0001751 0000144 00000013341 12700425755 012135 0 ustar hornik users Changes since version 0.4
===
* New features
* `list.ungroup` now supports `level` arguments to `unlist` a nested list recursively. (#102)
* `list.flatten` now accepts `classes` to filter list element recursively by class name.
* `list.expand` implements a list version of `expand.grid` (#107)
* Improvements
* Support loading and parsing from xml to list. (#43)
* `list.search` now uses `is.null` to clean the results.
* Add `list.unzip` to `List` object.
* `list.ungroup` now supports `group.names` to indicate whether to preserve group names.
* Implement better error handling mechanism in `list.all`, `list.takeWhile`, `list.skipWhile`, etc.
* `list.table` will directly call `table` upon input data if `...` is missing.
* Bug fixes
* Fix returned value of `list.unserialize`.
* `list.skip` returns the original data when asked to skip 0 elements.
* `list.skip` takes the first `n` elements when asked to skip a negative number of elements.
* Fix bug in lambda expression handling of `list.all` (#105)
Version 0.4
===
* New features
* Include a dataset `nyweather` scraped from [OpenWeatherMap](http://openweathermap.org/) (#2)
* `list.load` now supports text-based progress bar when `progress = TRUE` which is by default
enabled if over 5 files are to be loaded. (#92)
* New function `list.names` gives a list or vector names by mapping.
* New functions `list.first` and `list.last` find the first or last list element that meets a
given condition.
* New function `list.unzip` to transform a list of elements with similar structure into a
list of decoupled fields.
* Improvements
* Add error handling in several edge cases. (#18)
* `list.group` now supports grouping by multi-key which produces multi-level list. (#69)
* `list.load` now supports loading from multiple filenames given in character vector. (#74)
* `list.load` is now able to guess the file format even if the file type is not specified. (#76)
* `list.maps` now allows the usage of `..1`, `..2`, etc. to refer to unnamed arguments. (#80)
* `list.load` now supports merging and ungrouping as means to aggregating loaded results. (#82)
* `list.stack` now uses `data.table::setDF` to convert `data.table` to `data.frame` if
`data.table = FALSE`, which is done by reference and thus has higher performance.
* Bug fixes
* `list.search` now takes `n` as the number of returned vector rather than that of the
elements in all returned vectors, and is now able to jump out when the result set reaches
given capacity. (#47, #84)
* Fix how `list.table` deals with `NULL` values. (#73)
* Fix how wrapper functions deal with default arguments. (#75)
* Fix the dynamic scoping issues in `list.table`. (#86)
* `list.all` and `list.any` behave the same as `all` and `any` respectively when the input is empty. (#87)
* One-sided formula does not result in error now. (#89)
* `list.flatten` now preserves names as specified. (#90)
* Fix incorrect processing for fallback in `list.findi`. (#91)
* Fix the implementation in `list.group` working with multi-key. (#93)
* Fix incorrect ordering if some entries are multi-valued vectors and others and single-
valued. If `list.order` and `list.sort` encounter such situation, they now report
error rather than silently produced unreliable results. (#94)
* Fix inconsistencies in `list.all`, `list.any`, `list.first` and `list.last`.
* Deprecation
* `equal()` is removed and related packages are now suggested rather than imported. (#70)
* `summary.list()` is deprecated. (#70)
* No longer interprets `x -> f(x)` as a form a lambda expression. Use `x ~ f(x)` instead. (#54)
* `desc(x)` is no longer supported in `list.sort` and `list.order`. Use `-x` or `(x)` instead. (#66)
Version 0.3
===
API Break: `list.search` now evaluates expression recursively in a list and supports lambda expression.
Add `equal()` function for logical and fuzzy filtering and searching which supports exact equality, atomic equality, inclusion, pattern matching, string-distance tolerance.
Add `List()` to provide an environment in which most list functions are defined for light-weight chaining that does not rely on external operators.
Version 0.2.5
===
Add `list.apply` which is a wrapper function of lapply.
Add `list.search` that searches a list recursively.
Add exact search functions: `equal`, `unequal`, `unidentical`, `include`, and `exclude`.
Add fuzzy search functions: `like` and `unlike` based on stringdist package.
Enhance `list.clean` which now supports recursive cleaning.
Version 0.2.4
===
Add `list.common` that returns the common cases of all list member by expression.
Version 0.2.3
===
Improve performance (#26, #27)
Add `list.flatten` that flattens a nested list to one-level.
Version 0.2.2
===
Add `list.stack` that binds list members to a data.frame.
Add `list.zip` that combines multiple lists element-wisely.
Add `list.maps` that performs mapping over multiple lists.
Performance improvements.
Minor maintainence updates.
`list.cases` supports list-like cases
Fixed [#23](https://github.com/renkun-ken/rlist/issues/23)
Fixed [#25](https://github.com/renkun-ken/rlist/issues/25)
`list.select` no longer accepts explicit lambda expressions.
Vignettes updated
Version 0.2.1
===
Add new function `list.table`
Minor maintainence updates.
Fixed [#6](https://github.com/renkun-ken/rlist/issues/6)
Fixed [#11](https://github.com/renkun-ken/rlist/issues/11)
Fixed [#20](https://github.com/renkun-ken/rlist/issues/20)
Fixed [#21](https://github.com/renkun-ken/rlist/issues/21)
Version 0.2
===
Add `list.join`, `list.mapv`, `list.do`, `list.clean`, `list.parse`
Add vignettes
Version 0.1
===
Implement functions
rlist/data/ 0000755 0001751 0000144 00000000000 12700425754 012344 5 ustar hornik users rlist/data/nyweather.rda 0000644 0001751 0000144 00000044623 12700425754 015053 0 ustar hornik users BZh91AY&SYQY9} a># ɀXӫglֶim>g1VMlC 1UX x@x )=YWBP
QH5ӛ\O\aJ5T ` 0
z
f( 4=ꄔ 8ws@(4D444AѠ`F##S MF&@
F)OSM4&