-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fix/x3p_rotate
- Loading branch information
Showing
8 changed files
with
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#' Read all x3p files in a folder | ||
#' | ||
#' This function is provided with a path to a folder, it will search recursively for all x3p files within the folder, read the x3p files, and return the results as part of a tibble dataset. | ||
#' @param path character string to a folder | ||
#' @return tibble with two variables: source contains the file path to the x3p file, and x3p is a list variable of x3p objects. | ||
#' @export | ||
#' @importFrom dplyr as_tibble | ||
#' @examples | ||
#' # example code | ||
#' path <- dirname(system.file("csafe-logo.x3p", package="x3ptools")) | ||
#' x3p_read_folder(path) # show all x3p files installed with x3ptools | ||
x3p_read_folder <- function(path) { | ||
files <- dir(path, pattern = ".x3p$", ignore.case = TRUE, recursive = TRUE, full.names = TRUE, include.dirs = TRUE) | ||
if (length(files) == 0) { | ||
warning(sprintf("No x3p files found at '%s'", path)) | ||
return(dplyr::as_tibble(data.frame("source" = NULL, "x3p" = NULL))) | ||
} | ||
read_x3p_try <- function(...) try(x3ptools::x3p_read(...)) | ||
scans <- lapply(files, FUN = read_x3p_try) | ||
|
||
dplyr::as_tibble(data.frame(source = files, x3p = I(scans), stringsAsFactors = F)) | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
context("x3p_read_folder") | ||
|
||
|
||
test_that("x3p_read_folder works as expected", { | ||
|
||
# Test nonexistent file path | ||
expect_warning(x3p_read_folder(file.path("does", "not", "exist"))) | ||
|
||
# Test files installed with x3ptools | ||
path <- dirname(system.file("csafe-logo.x3p", package="x3ptools")) | ||
res <- x3p_read_folder(path) # show all x3p files installed with x3ptools | ||
expect_equal(names(res), c("source", "x3p")) | ||
expect_equal(class(res$x3p[[1]]), "x3p") | ||
}) |