Skip to content

Commit

Permalink
use data.table in CRAN and add more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunuuuu committed Oct 31, 2023
1 parent 6136949 commit 0ea0f41
Show file tree
Hide file tree
Showing 18 changed files with 84 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ 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)
Imports:
brio,
cli,
curl,
data.table (>= 1.14.9),
data.table,
httr2,
MCMCpack,
methods,
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions R/combine.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions R/dedup.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
4 changes: 4 additions & 0 deletions R/faers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions R/merge.R
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down
8 changes: 8 additions & 0 deletions R/methods-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion R/phv_.R
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
}

Expand Down
3 changes: 2 additions & 1 deletion R/standardize.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion R/unify.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}

Expand Down
2 changes: 2 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions man/FAERS-methods.Rd

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

2 changes: 1 addition & 1 deletion man/faers-package.Rd

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

5 changes: 5 additions & 0 deletions man/faers.Rd

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

3 changes: 3 additions & 0 deletions man/faers_before_period.Rd

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

7 changes: 7 additions & 0 deletions man/faers_combine.Rd

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

6 changes: 6 additions & 0 deletions man/faers_dedup.Rd

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

16 changes: 12 additions & 4 deletions man/faers_merge.Rd

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

0 comments on commit 0ea0f41

Please sign in to comment.