-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-who.R
More file actions
44 lines (40 loc) · 1.43 KB
/
test-who.R
File metadata and controls
44 lines (40 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library(testthat)
library(nc)
context('who')
source(system.file("test_engines.R", package="nc", mustWork=TRUE), local=TRUE)
if(suppressWarnings(requireNamespace("tidyr"))){
data(who, package="tidyr", envir=environment())
who.tall <- capture_melt_single(
who,
"new_?",
diagnosis=".*",
"_",
gender=".",
ages=list(
min.years="0|[0-9]{2}", as.numeric,
max.years=list("[0-9]{2}"), "?",
function(x)ifelse(x=="", Inf, as.numeric(x))),
value.name="count")
test_engines("capture_melt_single returns data.table", {
expect_is(who.tall, "data.table")
exp.names <- c(
"country", "iso2", "iso3", "year",
"diagnosis", "gender", "ages",
"min.years", "max.years", "count")
expect_identical(names(who.tall), exp.names)
})
test_engines("melt_multiple errors with one output column", {
expect_error({
capture_melt_multiple(who, variable=list(
column="new",
maybe="_?",
diagnosis=".*",
value="_",
gender=".",
ages=list(
min.years="0|[0-9]{2}", as.numeric,
max.years=list("[0-9]{2}"), "?",
function(x)ifelse(x=="", Inf, as.numeric(x)))))
}, "need multiple output columns, but only one value (new) captured in column group; either provide a different regex that captures more than one value in column group, or use capture_melt_single if you really want only one output column", fixed=TRUE)
})
}