From 130faa58ffc1e9b8f6c83de014004c06676261bd Mon Sep 17 00:00:00 2001 From: Toby Dylan Hocking Date: Wed, 18 Dec 2024 09:32:09 -0500 Subject: [PATCH] capture first glob test and doc --- R/capture_first_glob.R | 4 +-- man/capture_first_glob.Rd | 4 +-- tests/testthat/test-CRAN-glob.R | 49 +++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/R/capture_first_glob.R b/R/capture_first_glob.R index f6d2e6f..13f4aae 100644 --- a/R/capture_first_glob.R +++ b/R/capture_first_glob.R @@ -4,8 +4,8 @@ capture_first_glob <- structure(function (glob, ### string: glob specifying files to read. ..., -### pattern passed to capture_first_vec, used to get meta-data from -### file names. +### passed to capture_first_vec, should include pattern used on vector +### of file names to get meta-data. READ=fread ### function of one argument (file name) which returns a data table, ### default data.table::fread. diff --git a/man/capture_first_glob.Rd b/man/capture_first_glob.Rd index 07124be..e09a79a 100644 --- a/man/capture_first_glob.Rd +++ b/man/capture_first_glob.Rd @@ -7,8 +7,8 @@ file name, and combine with contents of each file.} ..., READ = fread)} \arguments{ \item{glob}{string: \code{glob} specifying files to read.} - \item{\dots}{pattern passed to \code{\link{capture_first_vec}}, used to get meta-data from -file names.} + \item{\dots}{passed to \code{\link{capture_first_vec}}, should include pattern used on vector +of file names to get meta-data.} \item{READ}{function of one argument (file name) which returns a data table, default \code{\link[data.table]{fread}}.} } diff --git a/tests/testthat/test-CRAN-glob.R b/tests/testthat/test-CRAN-glob.R index 4b19fee..6c310f6 100644 --- a/tests/testthat/test-CRAN-glob.R +++ b/tests/testthat/test-CRAN-glob.R @@ -7,11 +7,44 @@ db <- system.file("extdata/chip-seq-chunk-db", package="nc", mustWork=TRUE) glob <- paste0(db, "/*/*/counts/*") read.bedGraph <- function(f)data.table::fread( f, skip=1, col.names = c("chrom","start", "end", "count")) -data.chunk.pattern <- list( - data="H.*?", - "/", - chunk="[0-9]+", as.integer) -if(requireNamespace("R.utils"))test_engines("capture_first_glob returns expected columns", { - count.dt <- nc::capture_first_glob(glob, data.chunk.pattern, READ=read.bedGraph) - expect_identical(names(count.dt), c("data", "chunk", "chrom", "start", "end", "count")) -}) + +if(requireNamespace("R.utils")){ + + test_engines("capture_first_glob returns expected columns", { + count.dt <- nc::capture_first_glob( + glob, + data="H.*?", + "/", + chunk="[0-9]+", as.integer, + READ=read.bedGraph) + computed.cls <- sapply(count.dt, class) + expected.cls <- c( + data = "character", + chunk = "integer", + chrom = "character", + start = "integer", + end = "integer", + count = "integer") + expect_identical(computed.cls, expected.cls) + }) + + test_engines("capture_first_glob(type.convert) works", { + count.dt <- nc::capture_first_glob( + glob, + data="H.*?", + "/", + chunk="[0-9]+", + READ=read.bedGraph, + type.convert=TRUE) + computed.cls <- sapply(count.dt, class) + expected.cls <- c( + data = "character", + chunk = "integer", + chrom = "character", + start = "integer", + end = "integer", + count = "integer") + expect_identical(computed.cls, expected.cls) + }) + +}