Skip to content

Commit

Permalink
capture first glob test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Toby Dylan Hocking committed Dec 18, 2024
1 parent f57aa54 commit 130faa5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
4 changes: 2 additions & 2 deletions R/capture_first_glob.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions man/capture_first_glob.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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}}.}
}
Expand Down
49 changes: 41 additions & 8 deletions tests/testthat/test-CRAN-glob.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

}

0 comments on commit 130faa5

Please sign in to comment.