diff --git a/DESCRIPTION b/DESCRIPTION index 318403c..3ea39e3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,13 +14,19 @@ URL: https://pharmaverse.github.io/admiraldiscovery/ Depends: R (>= 4.1) Imports: + admiral, + admiralonco, + admiralophtha, + admiralvaccine, dplyr, glue, gt (>= 0.10.0), htmltools, - reactable + reactable, + rlang, + stringr, + tools Suggests: - admiral, knitr, rmarkdown, spelling diff --git a/NAMESPACE b/NAMESPACE index d2facb0..e761c03 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,12 +1,9 @@ # Generated by roxygen2: do not edit by hand +export(get_admrial_deprecated) +export(get_admrial_superseded) +export(get_fns_with_keyword) export(interactive_discovery) -importFrom(gt,cols_align) -importFrom(gt,cols_hide) -importFrom(gt,cols_label) -importFrom(gt,cols_width) -importFrom(gt,fmt_markdown) -importFrom(gt,gt) -importFrom(gt,opt_interactive) -importFrom(gt,pct) -importFrom(gt,sub_missing) +importFrom(rlang,"%||%") +importFrom(rlang,.data) +importFrom(rlang,.env) diff --git a/R/admiraldiscovery-package.R b/R/admiraldiscovery-package.R index c695bb7..cca014f 100644 --- a/R/admiraldiscovery-package.R +++ b/R/admiraldiscovery-package.R @@ -1,8 +1,14 @@ #' @keywords internal -#' @importFrom gt gt cols_hide cols_label fmt_markdown sub_missing -#' opt_interactive cols_width pct cols_align +#' @importFrom rlang .data .env %||% "_PACKAGE" ## usethis namespace: start ## usethis namespace: end NULL + +this_fn_is_not_used <- function() { + admiral::ae_event + admiralonco::bor_cr + admiralophtha::admiralophtha_adbcva + admiralvaccine::derive_vars_params +} diff --git a/R/get_fns_with_keyword.R b/R/get_fns_with_keyword.R new file mode 100644 index 0000000..31ab5e9 --- /dev/null +++ b/R/get_fns_with_keyword.R @@ -0,0 +1,89 @@ +#' Find Functions with Keyword +#' +#' @description +#' +#' `get_admrial_deprecated()`: Returns tibble of all deprecated functions in +#' the admiral, admiralonco, admiralophtha, and admiralvaccine packages. +#' +#' `get_admrial_superseded()`: Returns tibble of all superseded functions in +#' the admiral, admiralonco, admiralophtha, and admiralvaccine packages. +#' +#' `get_fns_with_keyword()`: Returns a character vector of functions that have +#' the passed keyword in the help file. For example, this function can be used to find all +#' deprecated or superseded functions in the admiral universe, as admiral +#' package include `#' @keywords deprecated` or `#' @keywords superseded` +#' in the function's roxygen2 comments. +#' +#' @inheritParams tools::Rd_db +#' @param keyword string of the keyword to identify +#' +#' @return a character vector of function names +#' @name get_keyword_fns +#' +#' @examples +#' get_admrial_deprecated() +#' get_admrial_superseded() +#' get_fns_with_keyword(package = "admiral", keyword = "superseded") +NULL + +#' @rdname get_keyword_fns +#' @export +get_admrial_deprecated <- function() { + c("admiral", "admiralonco", "admiralophtha", "admiralvaccine") |> + lapply( + function(x) { + dplyr::tibble( + package = x, + fn = get_fns_with_keyword(package = x, keyword = "deprecated") %||% NA_character_ + ) + } + ) |> + dplyr::bind_rows() |> + stats::na.omit() +} + +#' @rdname get_keyword_fns +#' @export +get_admrial_superseded <- function() { + c("admiral", "admiralonco", "admiralophtha", "admiralvaccine") |> + lapply( + function(x) { + dplyr::tibble( + package = x, + fn = get_fns_with_keyword(package = x, keyword = "superseded") %||% NA_character_ + ) + } + ) |> + dplyr::bind_rows() |> + stats::na.omit() +} + +#' @rdname get_keyword_fns +#' @export +get_fns_with_keyword <- function(package, keyword, lib.loc = NULL) { + # parse the help files in package + db <- tools::Rd_db(package = package) + + # data frame of all exported functions with indicator column indicating if + # keyword appears in the help file + df_all_fns <- + dplyr::tibble( + rd_file_name = names(db), + rd_file_contents = lapply(.data$rd_file_name, function(x) db[[x]] |> as.character() |> paste(collapse = "")), + alias = lapply(.data$rd_file_contents, extract_alias), # these are the function names + has_keyword = + lapply(.data$rd_file_contents, function(x) stringr::str_detect(x, pattern = glue::glue("\\\\keyword\\{[[keyword]]\\}", .open = "[[", .close = "]]"))) |> + unlist() + ) + + # return vector of all functions with matching keyword in help file + df_all_fns |> + dplyr::filter(.data$has_keyword) |> + dplyr::pull(.data$alias) |> + unlist(recursive = TRUE) +} + + +extract_alias <- function(x) { + stringr::str_extract_all(x, "(?<=\\\\alias\\{)(.*?)(?=\\})") +} diff --git a/R/interactive.R b/R/interactive.R index 83d7810..48a7a84 100644 --- a/R/interactive.R +++ b/R/interactive.R @@ -71,6 +71,14 @@ interactive_discovery <- function(type = c("gt", "reactable")) { .gt_discovery <- function() { admiraldiscovery::discovery |> + dplyr::left_join( + get_admrial_deprecated() |> dplyr::mutate(deprecated = TRUE), + by = c("package", "fn") + ) |> + dplyr::left_join( + get_admrial_superseded() |> dplyr::mutate(superseded = TRUE), + by = c("package", "fn") + ) |> dplyr::mutate( function_link = glue::glue("[`{package}::{fn}()`]({fn_url})"), .after = "fn_url" @@ -78,18 +86,28 @@ interactive_discovery <- function(type = c("gt", "reactable")) { dplyr::mutate( resource1_link = glue::glue("[{resource1_text}]({resource1_url})") ) |> - gt() |> - cols_hide(columns = c("fn", "fn_url", "package", "dataset_type", - "resource1_text", "resource1_url")) |> - cols_label( + gt::gt() |> + gt::cols_hide(columns = c("fn", "fn_url", "package", "dataset_type", + "resource1_text", "resource1_url", + "deprecated", "superseded")) |> + gt::cols_label( function_link = "Function", resource1_link = "Resources" ) |> - fmt_markdown(columns = c("function_link", "resource1_link")) |> - sub_missing(missing_text = "") |> - cols_width(c(dataset, dataset_type, variable) ~ pct(8)) |> - cols_align(align = "left") |> - opt_interactive( + # color deprecated/superseded functions + gt::tab_style( + style = gt::cell_fill(color = '#ffb3ba'), + locations = gt::cells_body(columns = gt::everything(), rows = .data$deprecated) + ) |> + gt::tab_style( + style = gt::cell_fill(color = '#ffffba'), + locations = gt::cells_body(columns = gt::everything(), rows = .data$superseded) + ) |> + gt::fmt_markdown(columns = c("function_link", "resource1_link")) |> + gt::sub_missing(missing_text = "") |> + gt::cols_width(c(dataset, dataset_type, variable) ~ gt::pct(8)) |> + gt::cols_align(align = "left") |> + gt::opt_interactive( use_search = TRUE, use_filters = TRUE, use_resizers = TRUE, diff --git a/inst/WORDLIST b/inst/WORDLIST index ce914f9..e726eee 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,3 +1,8 @@ ADaM ORCID +admiralonco +admiralophtha +admiralvaccine reactable +roxygen +tibble diff --git a/man/get_keyword_fns.Rd b/man/get_keyword_fns.Rd new file mode 100644 index 0000000..6df5dcc --- /dev/null +++ b/man/get_keyword_fns.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/get_fns_with_keyword.R +\name{get_keyword_fns} +\alias{get_keyword_fns} +\alias{get_admrial_deprecated} +\alias{get_admrial_superseded} +\alias{get_fns_with_keyword} +\title{Find Functions with Keyword} +\usage{ +get_admrial_deprecated() + +get_admrial_superseded() + +get_fns_with_keyword(package, keyword, lib.loc = NULL) +} +\arguments{ +\item{package}{a character string naming an installed package.} + +\item{keyword}{string of the keyword to identify} + +\item{lib.loc}{a character vector of directory names of \R libraries, + or \code{NULL}. The default value of \code{NULL} corresponds to all + libraries currently known. The specified library trees are used to + search for \code{package}.} +} +\value{ +a character vector of function names +} +\description{ +\code{get_admrial_deprecated()}: Returns tibble of all deprecated functions in +the admiral, admiralonco, admiralophtha, and admiralvaccine packages. + +\code{get_admrial_superseded()}: Returns tibble of all superseded functions in +the admiral, admiralonco, admiralophtha, and admiralvaccine packages. + +\code{get_fns_with_keyword()}: Returns a character vector of functions that have +the passed keyword in the help file. For example, this function can be used to find all +deprecated or superseded functions in the admiral universe, as admiral +package include \verb{#' @keywords deprecated} or \verb{#' @keywords superseded} +in the function's roxygen2 comments. +} +\examples{ +get_admrial_deprecated() +get_admrial_superseded() +get_fns_with_keyword(package = "admiral", keyword = "superseded") +}