Skip to content

Commit 09f0e66

Browse files
author
Yunuuuu
committed
refactor: update standalone scripts
1 parent 288f1c7 commit 09f0e66

23 files changed

Lines changed: 816 additions & 454 deletions

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Imports:
2323
MCMCpack,
2424
methods,
2525
openEBGM,
26-
rlang (>= 1.1.0),
26+
rlang,
2727
rvest,
2828
tools,
2929
utils,
@@ -58,6 +58,7 @@ Collate:
5858
'import-standalone-assert.R'
5959
'import-standalone-cli.R'
6060
'import-standalone-obj-type.R'
61+
'import-standalone-pkg.R'
6162
'load.R'
6263
'merge.R'
6364
'meta.R'
@@ -71,6 +72,7 @@ Collate:
7172
'signal.R'
7273
'standardize.R'
7374
'unify.R'
75+
'utils-assert.R'
7476
'utils-file.R'
7577
'utils-str.R'
7678
'utils.R'

NAMESPACE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ exportMethods(meddra_version)
7575
exportMethods(show)
7676
importClassesFrom(data.table,data.table)
7777
importFrom(BiocParallel,SerialParam)
78+
importFrom(cli,qty)
7879
importFrom(data.table,"%chin%")
7980
importFrom(data.table,":=")
8081
importFrom(data.table,.BY)
@@ -86,3 +87,11 @@ importFrom(data.table,.NGRP)
8687
importFrom(data.table,.SD)
8788
importFrom(data.table,data.table)
8889
importFrom(methods,show)
90+
importFrom(rlang,abort)
91+
importFrom(rlang,caller_arg)
92+
importFrom(rlang,caller_env)
93+
importFrom(rlang,ffi_standalone_check_number_1.0.7)
94+
importFrom(rlang,ffi_standalone_is_bool_1.0.7)
95+
importFrom(rlang,is_missing)
96+
importFrom(rlang,is_string)
97+
importFrom(rlang,is_vector)

R/athena.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
athena <- function(use = NULL, list = FALSE, force = FALSE, url = NULL) {
1616
assert_bool(list)
1717
assert_bool(force)
18-
assert_string(url, null_ok = TRUE)
18+
assert_string(url, allow_null = TRUE)
1919
if (!is.null(url) && !startsWith(url, "https")) {
2020
cli::cli_abort("{.arg url} must start with {.val https}")
2121
}
@@ -24,7 +24,7 @@ athena <- function(use = NULL, list = FALSE, force = FALSE, url = NULL) {
2424
if (list) {
2525
list.files(path)
2626
} else {
27-
assert_inclusive(use, use_athena, null_ok = TRUE)
27+
assert_inclusive(use, use_athena, allow_null = TRUE)
2828
use <- use %||% use_athena
2929
out <- athena_loads(path, use)
3030
if (length(use) == 1L) {

R/available.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#' faers_available(c(2011, 2023), c("q1", "q2"))
1414
#' @export
1515
faers_available <- function(years, quarters, force = FALSE, internal = FALSE) {
16-
assert_inclusive(quarters, faers_file_quarters)
16+
assert_inclusive(quarters, FAERS_FILE_QUARTERS)
1717
metadata <- faers_meta(force = force, internal = internal)
1818
years %in% metadata$year & quarters %chin% metadata$quarter
1919
}

R/class-FAERS.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ validate_faers <- function(object) {
7171
if (length(object@year) != length(object@quarter)) {
7272
return("the length of `@year` and `@quarter` must be the same")
7373
}
74-
if (!all(object@quarter %chin% faers_file_quarters)) {
74+
if (!all(object@quarter %chin% FAERS_FILE_QUARTERS)) {
7575
return(sprintf(
7676
"`@quarter` must be values in %s",
77-
oxford_comma(faers_file_quarters, final = "or")
77+
oxford_comma(FAERS_FILE_QUARTERS, final = "or")
7878
))
7979
}
8080
if (anyDuplicated(faers_period(object))) {
@@ -87,10 +87,10 @@ validate_faers <- function(object) {
8787
if (length(object@deduplication) != 1L || is.na(object@deduplication)) {
8888
return("@deduplication must be a bool, `TRUE` or `FALSE`")
8989
}
90-
if (!rlang::is_string(object@format, faers_file_format)) {
90+
if (!rlang::is_string(object@format, FAERS_FILE_FORMAT)) {
9191
return(sprintf(
9292
"`@format` must be a string of %s",
93-
oxford_comma(faers_file_format, final = "or")
93+
oxford_comma(FAERS_FILE_FORMAT, final = "or")
9494
))
9595
}
9696
TRUE
@@ -114,9 +114,9 @@ methods::setClass(
114114

115115
methods::setValidity("FAERSascii", function(object) {
116116
data <- object@data
117-
if (!all(faers_ascii_file_fields %chin% names(data))) {
117+
if (!all(FAERS_ASCII_FILE_FIELDS %chin% names(data))) {
118118
return(sprintf(
119-
"`@data` must contain the all ascii fields, including %s", oxford_comma(faers_ascii_file_fields)
119+
"`@data` must contain the all ascii fields, including %s", oxford_comma(FAERS_ASCII_FILE_FIELDS)
120120
))
121121
}
122122
if (!all(vapply(data, data.table::is.data.table, logical(1L)))) {

R/combine.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,13 @@ combine_faers_data <- function(x, type) {
135135
}
136136

137137
combine_faers_ascii_data <- function(x) {
138-
data_list <- lapply(faers_ascii_file_fields, function(field) {
138+
data_list <- lapply(FAERS_ASCII_FILE_FIELDS, function(field) {
139139
data.table::rbindlist(
140140
lapply(x, function(obj) obj@data[[field]]),
141141
fill = TRUE, use.names = TRUE
142142
)
143143
})
144-
data.table::setattr(data_list, "names", faers_ascii_file_fields)
144+
data.table::setattr(data_list, "names", FAERS_ASCII_FILE_FIELDS)
145145
data_list
146146
}
147147

R/download.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#' )
2020
#' @export
2121
faers_download <- function(years, quarters, format = NULL, dir = getwd(), ...) {
22-
format <- match.arg(format, faers_file_format)
23-
assert_string(dir, empty_ok = FALSE)
22+
format <- match.arg(format, FAERS_FILE_FORMAT)
23+
assert_string(dir, allow_empty = FALSE)
2424
if (format == "xml") {
2525
# only faers database has xml data files
2626
is_aers_pairs <- is_from_laers(years, quarters)

R/faers.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#' )
1313
#' @export
1414
faers <- function(years, quarters, format = NULL, dir = getwd(), compress_dir = dir, handle_opts = list()) {
15-
format <- match.arg(format, faers_file_format)
15+
format <- match.arg(format, FAERS_FILE_FORMAT)
1616
yq <- recycle_scalar(years = years, quarters = quarters)
1717
data.table::setDT(yq)
1818
yq <- unique(yq)

R/fda_drugs.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fda_drugs <- function(pattern = "Products", url = NULL,
2020
list = FALSE, force = FALSE) {
2121
assert_bool(list)
2222
assert_bool(force)
23-
assert_string(url, null_ok = TRUE)
23+
assert_string(url, allow_null = TRUE)
2424
file <- fda_drugs_file(url, force)
2525
fda_drugs_load(file, pattern = pattern, list = list)
2626
}

0 commit comments

Comments
 (0)