From f3b1559f9bd1061e954149fc1912273fff00402c Mon Sep 17 00:00:00 2001 From: Rich FitzJohn Date: Tue, 22 Oct 2024 21:45:38 +0100 Subject: [PATCH] Add location too --- R/outpack_tools.R | 3 +++ tests/testthat/test-outpack-tools.R | 14 +++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/R/outpack_tools.R b/R/outpack_tools.R index cb8760cd..f6424fdc 100644 --- a/R/outpack_tools.R +++ b/R/outpack_tools.R @@ -227,7 +227,10 @@ orderly_metadata_extract <- function(expr = NULL, name = NULL, location = NULL, envir <- environment() ret <- data_frame(id = ids) if (isTRUE(allow_remote) || length(location) > 0) { + loc <- root$index$location(location) + loc <- loc[loc$packet %in% ids, ] ret$local <- ids %in% root$index$unpacked() + ret$location <- I(unname(split(loc$location, loc$packet)[ids])) } for (i in seq_len(nrow(extract))) { from_i <- extract$from[[i]] diff --git a/tests/testthat/test-outpack-tools.R b/tests/testthat/test-outpack-tools.R index 06862e93..28c14d71 100644 --- a/tests/testthat/test-outpack-tools.R +++ b/tests/testthat/test-outpack-tools.R @@ -362,24 +362,28 @@ test_that("can differentiate remote metadata", { expect_equal(nrow(d1), 5) d2 <- orderly_metadata_extract(root = root, allow_remote = TRUE) - expect_equal(names(d2), c("id", "local", "name", "parameters")) + expect_equal(names(d2), c("id", "local", "location", "name", "parameters")) expect_equal(nrow(d2), 5) expect_equal(d2$local, rep(TRUE, 5)) + expect_equal(d2$location, I(rep(list("local"), 5))) d3 <- orderly_metadata_extract(root = root, location = "upstream") - expect_equal(names(d3), c("id", "local", "name", "parameters")) + expect_equal(names(d3), c("id", "local", "location", "name", "parameters")) expect_equal(nrow(d3), 0) d4 <- orderly_metadata_extract(root = root, allow_remote = TRUE, pull_metadata = TRUE) - expect_equal(names(d4), c("id", "local", "name", "parameters")) + expect_equal(names(d4), c("id", "local", "location", "name", "parameters")) expect_equal(nrow(d4), 8) expect_equal(d4$local, rep(c(TRUE, FALSE), c(5, 3))) + expect_equal(d4$location, I(rep(list("local", "upstream"), c(5, 3)))) suppressMessages(orderly_location_pull_packet(ids2[[2]], root = root)) - d5 <- orderly_metadata_extract(root = root, allow_remote = TRUE, - pull_metadata = TRUE) + d5 <- orderly_metadata_extract(root = root, allow_remote = TRUE) expect_equal(d5[names(d1)], d4[names(d1)]) expect_equal(d5$local, c(rep(TRUE, 5), FALSE, TRUE, FALSE)) + expect_equal(d5$location, + I(c(rep(list("local"), 5), + list("upstream", c("local", "upstream"), "upstream")))) })