Skip to content

Commit

Permalink
tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
wibeasley committed Sep 1, 2018
1 parent d4f0e5e commit 359a6b2
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 87 deletions.
9 changes: 2 additions & 7 deletions tests/testthat/test-table-nih-enrollment-pretty.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
library(testthat)
context("Pretty NIH Table")

d1 <- tibble::tribble(
ds_1a <- tibble::tribble(
~subject_id, ~gender, ~race, ~ethnicity,
1L, "Male", "Black or African American", "Not Hispanic or Latino",
2L, "Male", "Black or African American", "Not Hispanic or Latino",
Expand All @@ -13,12 +13,7 @@ d1 <- tibble::tribble(
8L, "Male", "White", "Hispanic or Latino"
)



test_that("Smoke Test", {
testthat::skip_on_cran()

observed <- table_nih_enrollment_pretty(d1)
observed <- table_nih_enrollment_pretty(ds_1a)
expect_true(!is.null(observed))
})

156 changes: 76 additions & 80 deletions tests/testthat/test-table-nih-enrollment.R
Original file line number Diff line number Diff line change
@@ -1,92 +1,88 @@
library(testthat)
context("NIH Table")

d1 <- tibble::tribble(
~subject_id, ~gender, ~race, ~ethnicity,
1L, "Male", "Black or African American", "Not Hispanic or Latino",
2L, "Male", "Black or African American", "Not Hispanic or Latino",
3L, "Female", "Black or African American", "Not Hispanic or Latino",
4L, "Male", "White", "Not Hispanic or Latino",
5L, "Male", "White", "Not Hispanic or Latino",
6L, "Female", "White", "Not Hispanic or Latino",
7L, "Male", "White", "Hispanic or Latino",
8L, "Male", "White", "Hispanic or Latino"
expected_1 <- structure(
list(gender = c("Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
"Male", "Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported"
), race = c("American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White"), ethnicity = c("Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity"),
n = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -63L)
)


ds_1a <- tibble::tribble(
~subject_id, ~gender, ~race, ~ethnicity,
1L, "Male", "Black or African American", "Not Hispanic or Latino",
2L, "Male", "Black or African American", "Not Hispanic or Latino",
3L, "Female", "Black or African American", "Not Hispanic or Latino",
4L, "Male", "White", "Not Hispanic or Latino",
5L, "Male", "White", "Not Hispanic or Latino",
6L, "Female", "White", "Not Hispanic or Latino",
7L, "Male", "White", "Hispanic or Latino",
8L, "Male", "White", "Hispanic or Latino"
)

test_that("Smoke Test", {
testthat::skip_on_cran()

observed <- table_nih_enrollment(d1)
test_that("Smoke Test", {
observed <- table_nih_enrollment(ds_1a)
expect_true(!is.null(observed))
})

test_that("d1", {
testthat::skip_on_cran()
expected <- structure(
list(gender = c("Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Female", "Female", "Female", "Female",
"Female", "Female", "Female", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
"Male", "Male", "Male", "Male", "Male", "Male", "Male", "Male",
"Male", "Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported",
"Unknown/Not Reported", "Unknown/Not Reported", "Unknown/Not Reported"
), race = c("American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White", "American Indian/Alaska Native", "American Indian/Alaska Native",
"American Indian/Alaska Native", "Asian", "Asian", "Asian", "Black or African American",
"Black or African American", "Black or African American", "More than One Race",
"More than One Race", "More than One Race", "Native Hawaiian or Other Pacific Islander",
"Native Hawaiian or Other Pacific Islander", "Native Hawaiian or Other Pacific Islander",
"Unknown or Not Reported", "Unknown or Not Reported", "Unknown or Not Reported",
"White", "White", "White"), ethnicity = c("Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity", "Hispanic or Latino",
"Not Hispanic or Latino", "Unknown/Not Reported Ethnicity"),
n = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
2L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2L, 2L, 0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 0L, 0L)), class = c("tbl_df", "tbl", "data.frame"
), row.names = c(NA, -63L)
)
observed <- table_nih_enrollment(d1) # dput(observed)

expect_equal(observed, expected)

test_that("ds_1a", {
observed <- table_nih_enrollment(ds_1a) # dput(observed)
expect_equal(observed, expected_1)
})

0 comments on commit 359a6b2

Please sign in to comment.