Skip to content

Commit

Permalink
reduce package size
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Nov 1, 2023
1 parent 97ccd08 commit 3b00ae7
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 76 deletions.
4 changes: 1 addition & 3 deletions R/meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ faers_meta_cache_read <- function(internal = FALSE) {
faers_cache_env[[".faers_meta_data"]] <- out$data
} else {
if (internal) {
out <- readRDS(system.file("extdata", "faers_meta_data.rds",
package = "faers"
))
out <- readRDS(internal_file("extdata", "faers_meta_data.rds"))
msg <- "Using internal FAERS metadata"
} else {
return(NULL)
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ internal_file <- function(...) {
}

pkg_nm <- function() {
packageName(topenv(environment()))
utils::packageName(topenv(environment()))
}

assert_internet <- function(call = rlang::caller_env()) {
Expand Down
3 changes: 3 additions & 0 deletions data-raw/DATASET.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ saveRDS(
list(data = meta, date = Sys.time()),
"inst/extdata/faers_meta_data.rds"
)

faers_sample(2004, "q1", dir = "inst/extdata")
faers_sample(2017, "q2", dir = "inst/extdata")
Binary file added inst/extdata/aers_ascii_2004q1.zip
Binary file not shown.
Binary file added inst/extdata/faers_ascii_2017q2.zip
Binary file not shown.
8 changes: 3 additions & 5 deletions tests/testthat/test_class.R
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
testthat::test_that("FAERS object and extractor works well", {
data <- suppressWarnings(faers(
c(2004, 2004, 2011, 2012),
c("q1", "q2", "q4", "q1"), "ascii",
dir = testthat::test_path("testdata"),
data <- faers_parse(
internal_file("extdata", "aers_ascii_2004q1.zip"),
compress_dir = tempdir()
))
)
data_list <- faers_data(data)
testthat::expect_true(is.list(data_list))
lapply(data_list, function(x) {
Expand Down
17 changes: 10 additions & 7 deletions tests/testthat/test_combine.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
testthat::test_that("combine FAERS ojbect works as expected", {
testthat::expect_no_error(data1 <- faers(2004, "q1", "ascii",
dir = testthat::test_path("testdata"), compress_dir = tempdir()
))
testthat::expect_no_error(data2 <- faers(2004, "q2", "ascii",
dir = testthat::test_path("testdata"), compress_dir = tempdir()
))
data3 <- faers_combine(list(data1, data2))
data1 <- faers_parse(
internal_file("extdata", "aers_ascii_2004q1.zip"),
compress_dir = tempdir()
)
data2 <- faers_parse(
internal_file("extdata", "faers_ascii_2017q2.zip"),
compress_dir = tempdir()
)
testthat::expect_no_error(data3 <- faers_combine(list(data1, data2)))
testthat::expect_warning(faers_combine(list(data1, data1)))
testthat::expect_s4_class(data3, "FAERSascii")
testthat::expect_false(data3@deduplication)
testthat::expect_false(data3@standardization)
Expand Down
14 changes: 9 additions & 5 deletions tests/testthat/test_faers.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
testthat::test_that("faers() function works as expected", {
testthat::expect_no_error(data1 <- faers(2004, "q1", "ascii",
dir = testthat::test_path("testdata"), compress_dir = tempdir()
dir = internal_file("extdata"),
compress_dir = tempdir()
))
testthat::expect_no_error(data2 <- faers(2004, "q2", "ascii",
dir = testthat::test_path("testdata"), compress_dir = tempdir()
testthat::expect_no_error(data2 <- faers(2017, "q2", "ascii",
dir = internal_file("extdata"),
compress_dir = tempdir()
))
testthat::expect_no_error(data3 <- faers(2004, c("q1", "q2"), "ascii",
dir = testthat::test_path("testdata"), compress_dir = tempdir()
testthat::expect_no_error(data3 <- faers(c(2004, 2017),
c("q1", "q2"), "ascii",
dir = internal_file("extdata"),
compress_dir = tempdir()
))
testthat::expect_s4_class(data3, "FAERSascii")
testthat::expect_false(data3@deduplication)
Expand Down
13 changes: 5 additions & 8 deletions tests/testthat/test_merge.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
data <- suppressWarnings(faers(
c(2004, 2004, 2011, 2012),
c("q1", "q2", "q4", "q1"), "ascii",
dir = testthat::test_path("testdata"),
compress_dir = tempdir()
))

testthat::test_that("`faers_merge` for FAERS ascii data works well", {

data <- faers(c(2004, 2017),
c("q1", "q2"), "ascii",
dir = internal_file("extdata"),
compress_dir = tempdir()
)
# internal don't modify data by reference and drug_seq match well
raw_indi <- data.table::copy(data$indi)
raw_ther <- data.table::copy(data$ther)
Expand Down
43 changes: 22 additions & 21 deletions tests/testthat/test_methods.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
data <- suppressWarnings(faers(
c(2004, 2004, 2011, 2012),
c("q1", "q2", "q4", "q1"), "ascii",
dir = testthat::test_path("testdata"),
data <- faers(c(2004, 2017),
c("q1", "q2"), "ascii",
dir = internal_file("extdata"),
compress_dir = tempdir()
))
)

testthat::test_that("faers_get works well", {
testthat::expect_s3_class(faers_get(data, "drug"), "data.table")
Expand Down Expand Up @@ -81,21 +80,23 @@ testthat::test_that("`$` works well", {
})

testthat::test_that("faers_keep works well", {
data1 <- faers_keep(data, "4204616")
testthat::expect_setequal(data1$drug$primaryid, "4204616")
testthat::expect_setequal(data1$indi$primaryid, "4204616")
testthat::expect_setequal(data1$reac$primaryid, "4204616")
testthat::expect_setequal(data1$demo$primaryid, "4204616")
testthat::expect_setequal(data1$ther$primaryid, "4204616")
testthat::expect_setequal(data1$rpsr$primaryid, "4204616")
testthat::expect_setequal(data1$outc$primaryid, "4204616")
ids1 <- sample(faers_primaryid(data), 1L)
data1 <- faers_keep(data, ids1)
testthat::expect_setequal(data1$drug$primaryid, ids1)
testthat::expect_in(data1$indi$primaryid, ids1)
testthat::expect_in(data1$reac$primaryid, ids1)
testthat::expect_in(data1$demo$primaryid, ids1)
testthat::expect_in(data1$ther$primaryid, ids1)
testthat::expect_in(data1$rpsr$primaryid, ids1)
testthat::expect_in(data1$outc$primaryid, ids1)

data <- faers_keep(data, c("4204616", "4261678"))
testthat::expect_setequal(data$demo$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$drug$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$indi$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$reac$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$ther$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$rpsr$primaryid, c("4204616", "4261678"))
testthat::expect_setequal(data$outc$primaryid, c("4204616", "4261678"))
ids2 <- sample(faers_primaryid(data), 2L)
data2 <- faers_keep(data, ids2)
testthat::expect_setequal(data2$demo$primaryid, ids2)
testthat::expect_in(data2$drug$primaryid, ids2)
testthat::expect_in(data2$indi$primaryid, ids2)
testthat::expect_in(data2$reac$primaryid, ids2)
testthat::expect_in(data2$ther$primaryid, ids2)
testthat::expect_in(data2$rpsr$primaryid, ids2)
testthat::expect_in(data2$outc$primaryid, ids2)
})
25 changes: 5 additions & 20 deletions tests/testthat/test_parse.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
testthat::test_that("Parsing FAERS ascii data works well", {
suppressWarnings(data <- faers_parse(
testthat::test_path("testdata", "aers_ascii_2011q4.zip"),
data <- faers_parse(
internal_file("extdata", "aers_ascii_2004q1.zip"),
compress_dir = tempdir()
))
)
testthat::expect_s4_class(data, "FAERSascii")
testthat::expect_null(data@meddra)
testthat::expect_false(data@deduplication)
Expand All @@ -17,28 +17,13 @@ testthat::test_that("Parsing FAERS ascii data works well", {
testthat::expect_false(anyNA(data@data$rpsr$primaryid))
testthat::expect_false(anyNA(data@data$outc$primaryid))

testthat::expect_equal(nrow(data@data$drug), 734093)
testthat::expect_equal(nrow(data@data$demo), 208489)
testthat::expect_equal(nrow(data@data$indi), 362256)
testthat::expect_equal(nrow(data@data$reac), 773537)
testthat::expect_equal(nrow(data@data$ther), 321898)
testthat::expect_equal(nrow(data@data$rpsr), 35032)
testthat::expect_equal(nrow(data@data$outc), 182057)

suppressWarnings(data2 <- faers_parse(
testthat::test_path("testdata", "aers_ascii_2012q1.zip"),
data2 <- faers_parse(internal_file("extdata", "aers_ascii_2004q1.zip"),
compress_dir = tempdir()
))
)
testthat::expect_s4_class(data2, "FAERSascii")
testthat::expect_null(data2@meddra)
testthat::expect_false(data2@deduplication)
testthat::expect_false(data2@standardization)
testthat::expect_equal(data2@format, "ascii")
testthat::expect_equal(nrow(data2@data$drug), 860983)
testthat::expect_equal(nrow(data2@data$demo), 231737)
testthat::expect_equal(nrow(data2@data$indi), 453398)
testthat::expect_equal(nrow(data2@data$reac), 838238)
testthat::expect_equal(nrow(data2@data$ther), 351431)
testthat::expect_equal(nrow(data2@data$rpsr), 44313)
testthat::expect_equal(nrow(data2@data$outc), 202719)
})
10 changes: 4 additions & 6 deletions tests/testthat/test_standardize.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
testthat::skip_on_ci()

data <- suppressWarnings(faers(
c(2004, 2004, 2011, 2012),
c("q1", "q2", "q4", "q1"), "ascii",
dir = testthat::test_path("testdata"),
data <- faers(c(2004, 2017),
c("q1", "q2"), "ascii",
dir = internal_file("extdata"),
compress_dir = tempdir()
))

)
data_std <- faers_standardize(data, "~/Data/MedDRA/MedDRA_26_1_English")

testthat::test_that("standardize FAERS ascii data works well", {
Expand Down

0 comments on commit 3b00ae7

Please sign in to comment.