diff --git a/DESCRIPTION b/DESCRIPTION index ef756e6..13a4498 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,7 +3,7 @@ Title: R interface for FDA Adverse Event Reporting System Version: 0.0.0.9000 Authors@R: person("Yun", "Peng", , "yunyunpp96@outlook.com", role = c("aut", "cre")) -Description: R interface for FDA Adverse Event Reporting System (FAERS). +Description: FAERS is a database for the spontaneous reporting of adverse events and medication errors involving human drugs and therapeutic biological products. faers is the bridge between FAERS and R. License: MIT + file LICENSE Depends: R (>= 3.5.0) @@ -11,7 +11,7 @@ Imports: brio, cli, curl, - data.table (>= 1.14.9), + data.table, httr2, MCMCpack, methods, @@ -22,7 +22,7 @@ Imports: xml2 Suggests: testthat (>= 3.0.0) -Remotes: Rdatatable/data.table +biocViews: Software, DataImport Encoding: UTF-8 ByteCompile: true Roxygen: list(markdown = TRUE) diff --git a/NAMESPACE b/NAMESPACE index 048dabc..55d0ae3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -3,6 +3,7 @@ export(faers) export(faers_available) export(faers_before_period) +export(faers_combine) export(faers_data) export(faers_dedup) export(faers_deleted_cases) diff --git a/R/combine.R b/R/combine.R index e1ec984..b536641 100644 --- a/R/combine.R +++ b/R/combine.R @@ -4,6 +4,13 @@ #' [FAERSxml] object #' @param x A list of [FAERSxml] or [FAERSascii] objects. #' @return A [FAERSxml] or [FAERSascii] object. +#' @examples +#' \dontrun{ +#' data1 <- faers(2012, "q1") +#' data2 <- faers(2013, "q4") +#' faers_combine(list(data1, data2)) +#' } +#' @export faers_combine <- function(x) { assert_(x, is.list, "a list") l <- length(x) diff --git a/R/dedup.R b/R/dedup.R index b26eb86..8f27569 100644 --- a/R/dedup.R +++ b/R/dedup.R @@ -2,6 +2,11 @@ #' @param object A [FAERSascii] object. #' @param ... Other arguments passed to specific methods. #' @return A [FAERSascii] object. +#' @examples +#' \dontrun{ +#' data <- faers(c(2012, 2013), c("q1", "q3")) +#' faers_dedup(data) +#' } #' @export #' @name faers_dedup methods::setGeneric("faers_dedup", function(object, ...) { diff --git a/R/faers.R b/R/faers.R index 67aae0c..34f2ab6 100644 --- a/R/faers.R +++ b/R/faers.R @@ -4,6 +4,10 @@ #' @param handle_opts Extra handle options passed to each request #' [new_handle][curl::new_handle]. #' @return A [FAERSxml] or [FAERSascii] object. +#' @examples +#' \dontrun{ +#' data <- faers(c(2012, 2013), c("q1", "q3")) +#' } #' @export faers <- function(years, quarters, format = NULL, dir = getwd(), compress_dir = dir, handle_opts = list()) { format <- match.arg(format, faers_file_format) diff --git a/R/merge.R b/R/merge.R index 4fc17dc..e60da35 100644 --- a/R/merge.R +++ b/R/merge.R @@ -11,6 +11,12 @@ #' Only the initial instance, of the "caseid" column will be preserved. #' #' @return A [data.table][data.table::data.table] object. +#' @examples +#' \dontrun{ +#' data <- faers(c(2012, 2013), c("q1", "q3")) +#' faers_merge(data, "indi") +#' faers_merge(data, c("demo", "indi")) +#' } #' @export #' @name faers_merge methods::setGeneric("faers_merge", function(object, ...) { diff --git a/R/methods-utils.R b/R/methods-utils.R index 9d72260..79d7fa3 100644 --- a/R/methods-utils.R +++ b/R/methods-utils.R @@ -24,6 +24,14 @@ #' - `faers_filter`: apply a function to extract wanted `primaryid`, then use #' `faers_keep` to filter. #' @export +#' @examples +#' \dontrun{ +#' data <- faers(2012, "q1") +#' faers_get(data, "indi") +#' data[["indi"]] +#' faers_get(data, "demo") +#' data[["demo"]] +#' } #' @rdname FAERS-methods methods::setGeneric("faers_get", function(object, ...) { methods::makeStandardGeneric("faers_get") diff --git a/R/phv_.R b/R/phv_.R index 0fc3cf0..94ea6a3 100644 --- a/R/phv_.R +++ b/R/phv_.R @@ -249,7 +249,7 @@ phv_bcpnn_mcmc <- function(a, b, c, d, alpha = 0.05, n_mcmc = 1e5L) { out <- data.table::as.data.table(do.call("rbind", out)) data.table::setnames(out, c("ci_low", "ci_high")) out[, ic := ic] - data.table::setcolorder(out, "ic", before = 1L) + data.table::setcolorder(out, c("ic", "ci_low", "ci_high")) out[] } diff --git a/R/standardize.R b/R/standardize.R index 318a28c..bb59baa 100644 --- a/R/standardize.R +++ b/R/standardize.R @@ -274,8 +274,9 @@ athena_standardize_drug <- function(terms, path = NULL, force = FALSE) { ))) )] out <- data$concept[match(..__mapped_concept_ids__.., concept_id)] # nolint + old_nms <- data.table::copy(names(out)) out[, athena_drug_names := terms] # nolint - data.table::setcolorder(out, "athena_drug_names", before = 1L) + data.table::setcolorder(out, c("athena_drug_names", old_nms)) } utils::globalVariables(c( diff --git a/R/unify.R b/R/unify.R index 9623eb4..8eb7b64 100644 --- a/R/unify.R +++ b/R/unify.R @@ -15,8 +15,9 @@ unify_ascii <- function(data, field, year, quarter) { drug = unify_ascii_drug(data, year, quarter), outc = unify_ascii_outc(data, year, quarter) ) + old_nms <- data.table::copy(names(data)) data[, c("year", "quarter") := list(year, quarter)] - data.table::setcolorder(data, c("year", "quarter"), before = 1L) + data.table::setcolorder(data, c("year", "quarter", old_nms)) data[!is.na(primaryid)] } diff --git a/R/utils.R b/R/utils.R index f0800c8..292cdd4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -16,6 +16,8 @@ is_from_laers <- function(years, quarters) { #' @param inclusive A bool, whether to include the period specifid. #' @return An atomic logical with the same length of the max length of `years` #' and `quarters`. +#' @examples +#' faers_before_period(c(2011, 2012), c("q1", "q3"), 2011, "q2") #' @export faers_before_period <- function(years, quarters, y, q, inclusive = TRUE) { periods <- recycle_scalar(years = years, quarters = quarters) diff --git a/man/FAERS-methods.Rd b/man/FAERS-methods.Rd index cf8fca6..32a1fda 100644 --- a/man/FAERS-methods.Rd +++ b/man/FAERS-methods.Rd @@ -101,3 +101,12 @@ better to run \link[=FAERS]{faers}. \code{faers_keep} to filter. } } +\examples{ +\dontrun{ + data <- faers(2012, "q1") + faers_get(data, "indi") + data[["indi"]] + faers_get(data, "demo") + data[["demo"]] +} +} diff --git a/man/faers-package.Rd b/man/faers-package.Rd index d641c64..b02661e 100644 --- a/man/faers-package.Rd +++ b/man/faers-package.Rd @@ -6,7 +6,7 @@ \alias{_PACKAGE} \title{faers: R interface for FDA Adverse Event Reporting System} \description{ -R interface for FDA Adverse Event Reporting System (FAERS). +FAERS is a database for the spontaneous reporting of adverse events and medication errors involving human drugs and therapeutic biological products. faers is the bridge between FAERS and R. } \author{ \strong{Maintainer}: Yun Peng \email{yunyunpp96@outlook.com} diff --git a/man/faers.Rd b/man/faers.Rd index 882869f..8c258eb 100644 --- a/man/faers.Rd +++ b/man/faers.Rd @@ -37,3 +37,8 @@ A \link{FAERSxml} or \link{FAERSascii} object. \description{ Download and parse FAERS Quarterly Data files } +\examples{ +\dontrun{ + data <- faers(c(2012, 2013), c("q1", "q3")) +} +} diff --git a/man/faers_before_period.Rd b/man/faers_before_period.Rd index ce661d3..92effca 100644 --- a/man/faers_before_period.Rd +++ b/man/faers_before_period.Rd @@ -25,3 +25,6 @@ and \code{quarters}. \description{ Test whether years and quarters are before specified period } +\examples{ +faers_before_period(c(2011, 2012), c("q1", "q3"), 2011, "q2") +} diff --git a/man/faers_combine.Rd b/man/faers_combine.Rd index 73d2f03..aecfde8 100644 --- a/man/faers_combine.Rd +++ b/man/faers_combine.Rd @@ -16,3 +16,10 @@ A \link{FAERSxml} or \link{FAERSascii} object. Packed all \link{FAERSascii} or \link{FAERSxml} objects into a single \link{FAERSascii} or \link{FAERSxml} object } +\examples{ +\dontrun{ + data1 <- faers(2012, "q1") + data2 <- faers(2013, "q4") + faers_combine(list(data1, data2)) +} +} diff --git a/man/faers_dedup.Rd b/man/faers_dedup.Rd index d2d0f3e..7f5d129 100644 --- a/man/faers_dedup.Rd +++ b/man/faers_dedup.Rd @@ -29,3 +29,9 @@ A \link{FAERSascii} object. \description{ Tidy up FAERS Quarterly Data with duplicate records removed } +\examples{ +\dontrun{ + data <- faers(c(2012, 2013), c("q1", "q3")) + faers_dedup(data) +} +} diff --git a/man/faers_merge.Rd b/man/faers_merge.Rd index 6dd8a74..51a726e 100644 --- a/man/faers_merge.Rd +++ b/man/faers_merge.Rd @@ -26,10 +26,11 @@ faers_merge(object, ...) \item{all}{logical; \code{all = TRUE} is shorthand to save setting both \code{all.x = TRUE} and \code{all.y = TRUE}.} -\item{all.x}{logical; if \code{TRUE}, rows from \code{x} which have no matching row -in \code{y} are included. These rows will have 'NA's in the columns that are usually -filled with values from \code{y}. The default is \code{FALSE} so that only rows with -data from both \code{x} and \code{y} are included in the output.} +\item{all.x}{logical; if \code{TRUE}, then extra rows will be added to the +output, one for each row in \code{x} that has no matching row in \code{y}. +These rows will have 'NA's in those columns that are usually filled with values +from \code{y}. The default is \code{FALSE}, so that only rows with data from both +\code{x} and \code{y} are included in the output.} \item{all.y}{logical; analogous to \code{all.x} above.} } @@ -52,3 +53,10 @@ Only the initial instance, of the "caseid" column will be preserved. You'd better only merge necessary data, otherwise a lot of memory will be consumed to merge all fields data. } +\examples{ +\dontrun{ + data <- faers(c(2012, 2013), c("q1", "q3")) + faers_merge(data, "indi") + faers_merge(data, c("demo", "indi")) +} +}