Skip to content

Commit

Permalink
version++
Browse files Browse the repository at this point in the history
  • Loading branch information
tdhock committed Feb 7, 2024
2 parents 5ddb813 + d2b7a73 commit fb8d102
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: nc
Maintainer: Toby Dylan Hocking <[email protected]>
Author: Toby Dylan Hocking
Version: 2024.1.31
Version: 2024.2.6
License: GPL-3
Title: Named Capture to Data Tables
Description: User-friendly functions for extracting a data
Expand Down
10 changes: 9 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
Changes in version 2024.1.31
Changes in version 2024.2.6

- if(requireNamespace(suggested)) in tests, thanks CRAN.

Changes in version 2024.2.1

- Fix vignette 7 by adding if(requireNamespace("arrow")).

Changes in version 2024.1.30

- Imports data.table >= 1.15.0.
- Remove code which uses old pre-measure data.table.
Expand Down
3 changes: 3 additions & 0 deletions README.org
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ The main functions provided in nc are:
- [[https://cloud.r-project.org/web/packages/nc/vignettes/v5-helpers.html][Vignette 5]] explains how to use helper functions for creating complex
regular expressions.
- [[https://cloud.r-project.org/web/packages/nc/vignettes/v6-engines.html][Vignette 6]] explains how to use different regex engines.
- [[https://cloud.r-project.org/web/packages/nc/vignettes/v7-capture-glob.html][Vignette 7]] explains how to read regularly named files, and use a
regex to extract meta-data from the file names, using
=nc::capture_first_glob=.

*** Choice of regex engine

Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-CRAN-df.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(testthat)
context("df")
source(system.file("test_engines.R", package="nc", mustWork=TRUE), local=TRUE)

test_engines("default/specified engine respected", {
if(requireNamespace("stringi"))test_engines("default/specified engine respected", {
subject.df <- data.frame(f="foo", b="bar")
match.dt <- capture_first_df(
subject.df,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-CRAN-glob.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ data.chunk.pattern <- list(
data="H.*?",
"/",
chunk="[0-9]+", as.integer)
test_engines("capture_first_glob returns expected columns", {
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"))
})
35 changes: 16 additions & 19 deletions tests/testthat/test-CRAN-longer.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@ library(data.table)
library(testthat)
source(system.file("test_engines.R", package="nc", mustWork=TRUE), local=TRUE)

if("measure" %in% ls(asNamespace("data.table"))){
test_engines("single spec works", {
(single.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", dim=".*", values_to="cm"))
expect_identical(sort(names(single.spec)), c(".name", ".value", "dim", "part"))
})

test_engines("single spec works", {
(single.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", dim=".*", values_to="cm"))
expect_identical(sort(names(single.spec)), c(".name", ".value", "dim", "part"))
})
test_engines("multiple spec works", {
(multiple.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", column=".*"))
expect_identical(sort(names(multiple.spec)), c(".name", ".value", "part"))
})

test_engines("multiple spec works", {
(multiple.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", column=".*"))
expect_identical(sort(names(multiple.spec)), c(".name", ".value", "part"))
})
if(requireNamespace("tidyr"))test_engines("missing spec works", {
missing.col <- data.table(Sepal.Length=1, Sepal.Width=2, Petal.Length=3)
(missing.spec <- nc::capture_longer_spec(missing.col, part=".*", "[.]", column=".*"))
computed.df <- tidyr::pivot_longer_spec(missing.col, missing.spec)
sorted.dt <- data.table(computed.df)[order(part)]
expected.dt <- data.table(part=c("Petal", "Sepal"), Length=c(3, 1), Width=c(NA, 2))
expect_identical(sorted.dt, expected.dt)
})

test_engines("missing spec works", {
missing.col <- data.table(Sepal.Length=1, Sepal.Width=2, Petal.Length=3)
(missing.spec <- nc::capture_longer_spec(missing.col, part=".*", "[.]", column=".*"))
computed.df <- tidyr::pivot_longer_spec(missing.col, missing.spec)
sorted.dt <- data.table(computed.df)[order(part)]
expected.dt <- data.table(part=c("Petal", "Sepal"), Length=c(3, 1), Width=c(NA, 2))
expect_identical(sorted.dt, expected.dt)
})

}
41 changes: 19 additions & 22 deletions tests/testthat/test-CRAN-measure.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,24 @@ library(data.table)
context("measure")
source(system.file("test_engines.R", package="nc", mustWork=TRUE), local=TRUE)

if("measure" %in% ls(asNamespace("data.table"))){
DT <- data.table(a_1=10, b_2=21, a_2=20)
test_engines("measure single value", {
out <- melt(DT, measure.vars=nc::measure(
letter="[ab]", "_", number="[12]", as.integer))
expected <- data.table(
letter=c("a","b","a"),
number=as.integer(c(1,2,2)),
value=c(10,21,20))
expect_identical(out, expected)
})

DT <- data.table(a_1=10, b_2=21, a_2=20)
test_engines("measure single value", {
out <- melt(DT, measure.vars=nc::measure(
letter="[ab]", "_", number="[12]", as.integer))
expected <- data.table(
letter=c("a","b","a"),
number=as.integer(c(1,2,2)),
value=c(10,21,20))
expect_identical(out, expected)
})
test_engines("measure multiple values", {
out <- melt(DT, measure.vars=nc::measure(
column="[ab]", "_", number="[12]", as.integer))
expected <- data.table(
number=as.integer(c(1,2)),
a=c(10,20),
b=c(NA,21))
expect_identical(out, expected)
})

test_engines("measure multiple values", {
out <- melt(DT, measure.vars=nc::measure(
column="[ab]", "_", number="[12]", as.integer))
expected <- data.table(
number=as.integer(c(1,2)),
a=c(10,20),
b=c(NA,21))
expect_identical(out, expected)
})

}
2 changes: 1 addition & 1 deletion tests/testthat/test-CRAN-subject.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ test_that("capture_first_df does not use s arg for subject", {
expect_identical(dt, expected.dt)
})

test_that("capture_melt_single does not use s arg for subject", {
if(requireNamespace("stringi"))test_that("capture_melt_single does not use s arg for subject", {
subject <- data.frame(family=1, s2=2, s3=3)
## also make sure that engine is passed thru (not interpreted as a
## capture group).
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-CRAN-vec.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ source(system.file("test_engines.R", package="nc", mustWork=TRUE), local=TRUE)
## string, and an optional match that fails.
inames <- c("Species", "Petal.Length", "Sepal.Width")
sapply(c("[^.]*(.*)", "[^.]*([.].*)?"), function(pat){
stringi::stri_match_first_regex(inames, pat)
if(requireNamespace("stringi"))stringi::stri_match_first_regex(inames, pat)
})

test_engines("match nothing in required group is empty string", {
Expand Down
2 changes: 1 addition & 1 deletion vignettes/v7-capture-glob.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ with three variables encoded in the file path (data, chunk, part).
The code below reads one of the files back into R:

```{r}
data.table::fread(hive.files[1])
data.table::fread(hive.files[1])
```

The output above indicates that the file only has four columns (and is missing the variables which are encoded in the file path).
Expand Down

0 comments on commit fb8d102

Please sign in to comment.