-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Draft list_select, check_arg_is_list
- tests - pkgdown - documentation
- Loading branch information
Showing
9 changed files
with
96 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#' @title Select Data Tibbles from Named Lists | ||
#' | ||
#' @description | ||
#' `list_select()` helps users easily select data tibbles from named lists. This | ||
#' function uses <[`tidy-select`][tidyr_tidy_select]> syntax to specify which elements to extract. | ||
#' | ||
#' @details | ||
#' `list_select()` can be used with any named list, and is typically used in | ||
#' conjunction with [extract_tibbles()] to pull out named data tibbles of interest | ||
#' for analytic operations. | ||
#' | ||
#' @param list A named list from which data tibbles are to be selected. Required. | ||
#' @param tbls <[`tidy-select`][tidyr_tidy_select]> The names of the data tibbles to select from the list. Required. | ||
#' | ||
#' @return A named list of selected data tibbles. | ||
#' | ||
#' @examples | ||
#' my_list <- extract_tibbles(superheroes_supertbl) | ||
#' | ||
#' list_select(my_list, starts_with("hero")) | ||
#' | ||
#' @export | ||
|
||
list_select <- function(list, tbls = everything()) { | ||
# Check args ---- | ||
check_arg_is_list(list) | ||
|
||
tbls <- eval_select(data = list, expr = enquo(tbls)) | ||
list[tbls] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
test_that("list_select works", { | ||
db <- extract_tibbles(supertbl = superheroes_supertbl) | ||
|
||
# list_select returns everything by default | ||
everything_out <- list_select(db) | ||
|
||
expect_equal(db, everything_out) | ||
|
||
# list_select works with tidyselect valid specification | ||
selected_out <- list_select(db, starts_with("hero")) | ||
|
||
expect_equal(db[1], selected_out) | ||
|
||
# list_select returns empty tidyselect | ||
empty_out <- list_select(db, starts_with("empty")) | ||
|
||
# Create an empty named list | ||
empty_named_list <- list() | ||
names(empty_named_list) <- character(0) | ||
|
||
expect_equal(empty_out, empty_named_list) | ||
|
||
# list_select errors for hard-coded strings that don't exist | ||
expect_error(list_select(db, c("heroes_information", "fake_tbl"))) | ||
}) |