Skip to content

Commit

Permalink
meddra function augment argument primary_soc to help save the ful…
Browse files Browse the repository at this point in the history
…l meddra data
  • Loading branch information
Yunuuuu committed Jul 23, 2024
1 parent c6b63e8 commit 6a63a02
Show file tree
Hide file tree
Showing 11 changed files with 574 additions and 555 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: faers
Title: R interface for FDA Adverse Event Reporting System
Version: 1.1.4
Version: 1.1.5
Authors@R:
c(
person("Yun", "Peng", , "yunyunp96@163.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2801-3332")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# faers 0.99.0

* Initial Bioconductor submission.

# faers 1.1.4

* fix error when download failed

* meddra augment additional argument `primary_soc` to help save the full meddra data
6 changes: 4 additions & 2 deletions R/meddra.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ NULL
#' @param path A string, define the path of MedDRA directory.
#' @param add_smq A bool, indicates whether Standardised MedDRA Queries (SMQ)
#' should be added. If `TRUE`, "smq_content.asc", and "smq_list.asc" must exist.
#' @param primary_soc A bool, indicates whether keep primary soc only.
#' @export
#' @rdname MedDRA-class
meddra <- function(path, add_smq = FALSE) {
hierarchy <- meddra_load_hierarchy(path, primary_soc = FALSE)
meddra <- function(path, add_smq = FALSE, primary_soc = FALSE) {
assert_bool(primary_soc)
hierarchy <- meddra_load_hierarchy(path, primary_soc = primary_soc)
version <- meddra_load_version(path)
if (add_smq) {
smq_data <- meddra_load_smq(path)
Expand Down
2 changes: 1 addition & 1 deletion R/period.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ faers_before_period <- function(years, quarters, y, q, inclusive = TRUE) {
if (!rlang::is_string(q, string = faers_file_quarters)) {
cli::cli_abort("{.arg q} must be a string in {.val {faers_file_quarters}}")
}
assert_bool(inclusive, 1L)
assert_bool(inclusive)
do.call(
is_before_period,
c(periods, list(y = y, q = q, inclusive = inclusive))
Expand Down
2 changes: 1 addition & 1 deletion R/standardize.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ methods::setMethod("faers_standardize", "FAERSascii", function(object, meddra_pa
# standardize PT terms
# for indi
assert_string(meddra_path)
meddra_data <- meddra(meddra_path, add_smq = add_smq)
meddra_data <- meddra(meddra_path, add_smq = add_smq, primary_soc = TRUE)
# https://stackoverflow.com/questions/70181149/is-a-saved-and-loaded-data-table-with-qs-a-correct-data-table
# fix error: when load a saved FAERS object, don't change by reference
cli::cli_alert("standardize {.field Preferred Term} in indi")
Expand Down
665 changes: 333 additions & 332 deletions README.html

Large diffs are not rendered by default.

431 changes: 216 additions & 215 deletions README.md

Large diffs are not rendered by default.

Binary file modified inst/extdata/faers_meta_data.rds
Binary file not shown.
Binary file modified inst/extdata/standardized_data.rds
Binary file not shown.
4 changes: 3 additions & 1 deletion man/MedDRA-class.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions tests/testthat/test_meddra.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,26 @@ testthat::test_that("meddra works well", {
testthat::expect_true(rlang::is_string(meddra_load_version(path), "26.1"))
testthat::expect_s3_class(data <- meddra_load_hierarchy(path), "data.table")
testthat::expect_true(all(data$primary_soc_fg == "Y"))
testthat::expect_true(anyDuplicated(data$llt_code) == 0L)
testthat::expect_s3_class(data <- meddra_load_smq(path), "data.table")

# meddra() works well
testthat::expect_s4_class(data <- meddra(path), "MedDRA")
testthat::expect_s4_class(
data <- meddra(path, primary_soc = TRUE), "MedDRA"
)
testthat::expect_true(rlang::is_string(meddra_version(data), "26.1"))
testthat::expect_s3_class(hierarchy <- meddra_hierarchy(data), "data.table")
testthat::expect_null(hierarchy$smq_code)
testthat::expect_true(all(hierarchy$primary_soc_fg == "Y"))
testthat::expect_true(anyDuplicated(hierarchy$llt_code) == 0L)
testthat::expect_null(meddra_smq(data))

# meddra() with add_smq = TRUE, works well
testthat::expect_s4_class(data <- meddra(path, TRUE), "MedDRA")
testthat::expect_s4_class(data <- meddra(path, TRUE, TRUE), "MedDRA")
testthat::expect_true(rlang::is_string(meddra_version(data), "26.1"))
testthat::expect_s3_class(hierarchy <- meddra_hierarchy(data), "data.table")
testthat::expect_true(any(!is.na(hierarchy$smq_code)))
testthat::expect_true(all(hierarchy$primary_soc_fg == "Y"))
testthat::expect_true(anyDuplicated(hierarchy$llt_code) == 0L)
testthat::expect_s3_class(meddra_smq(data), "data.table")
})

0 comments on commit 6a63a02

Please sign in to comment.