diff --git a/R/cache.R b/R/cache.R index e75a6b5..af25203 100644 --- a/R/cache.R +++ b/R/cache.R @@ -29,16 +29,13 @@ get_dir_size <- function(path) { #' @export #' @return A dataframe of the directories list_cache_files <- function() { - df <- list.files(get_cache_dir(), full.names=TRUE) - if (length(df) == 0) { return(data.frame()) } - df <- df[sapply(df, dir.exists, USE.NAMES=FALSE)] # keep dirs only - df <- data.frame(Path=df, Name=basename(df)) - df$Size <- sapply(df$Path, get_dir_size) - df + paths <- list.files(get_cache_dir(), full.names=TRUE) + if (length(paths) == 0) { return(data.frame()) } + paths <- paths[sapply(paths, dir.exists, USE.NAMES=FALSE)] # keep dirs only + do.call(rbind, lapply(paths, rcldf::get_details)) } - #' Removes all files in the cache directory #' #' @export diff --git a/R/get_details.R b/R/get_details.R new file mode 100644 index 0000000..6264b72 --- /dev/null +++ b/R/get_details.R @@ -0,0 +1,16 @@ + +#' Returns a dataframe of with details on the CLDF dataset in `path`. +#' @param path the path to resolve +#' @export +#' @return A dataframe. +get_details <- function(path) { + md <- rcldf::resolve_path(path) + data.frame( + Title=md$metadata$`dc:title`, + Path=path, + Size=get_dir_size(dirname(path)), + Citation=md$metadata$`dc:bibliographicCitation`, + ConformsTo=md$metadata$`dc:conformsTo` + ) +} + diff --git a/tests/testthat/test_get_details.R b/tests/testthat/test_get_details.R new file mode 100644 index 0000000..f3cfc7f --- /dev/null +++ b/tests/testthat/test_get_details.R @@ -0,0 +1,9 @@ +test_that("test get_details", { + df <- get_details("examples/wals_1A_cldf/StructureDataset-metadata.json") + expect_is(df, 'data.frame') + expect_equal(df$Title, 'The Dataset') + expect_equal(df$Size, 13696) + expect_equal(df$Citation, 'Cite me like this!') + expect_equal(df$ConformsTo, 'http://cldf.clld.org/v1.0/terms.rdf#StructureDataset') + +}) \ No newline at end of file