R/rt_all.R

Defines functions rt_all

Documented in rt_all

#' Identify and extract transparency statements from a TXT file.
#'
#' Takes a TXT file and examines whether any statements of Conflicts of Interest
#'     (COI), Funding, Protocol Registration, Novelty or Replication exist. If
#'     any such statements are found, it also extracts the relevant text.
#'
#' @param filename The name of the TXT file as a string.
#' @return A dataframe of results. It returns the PMID of the article (if this
#'     was included in the filename and preceded by "PMID"), whether each of the
#'     five indicators of transparency (COI, Funding, Registration, Novelty and
#'     Replication) was identified, the relevant text identified, and whether
#'     each labelling function identified relevant text or not. The labelling
#'     functions are returned to add flexibility in how this package is used;
#'     for example, future definitions of Registration may differ from the one
#'     we used. If a labelling function returns NA it means that it was not run.
#' @examples
#' \donttest{
#' # Write a short example article to a temporary text file.
#' filepath <- file.path(tempdir(), "PMID00000000-PMC0000000.txt")
#' writeLines(c(
#'   "To our knowledge, this is the first study of its kind.",
#'   "Conflicts of interest: none declared.",
#'   "This work was supported by the National Institutes of Health (R01-000000).",
#'   "The protocol was registered at ClinicalTrials.gov (NCT00000000).",
#'   "All data and code are available at https://github.com/example/repo.",
#'   "We independently replicated the original analysis."
#' ), filepath)
#'
#' # Identify and extract indicators of transparency.
#' results_table <- rt_all(filepath)
#' }
#' @export
rt_all <- function(filename) {

  # Avoid automated checking warning in R package development
  article <- pmid <- NULL

  # Extract indicators
  # TODO Modify functions to avoid loading the TXT file multiple times.
  out_ls <- list(
    coi_df        = rt_coi(filename) %>% dplyr::select(!(article:pmid)),
    fund_df       = rt_fund(filename) %>% dplyr::select(!(article:pmid)),
    register_df   = rt_register(filename),
    novelty_df    = rt_novelty(filename) %>% dplyr::select(!(article:pmid)),
    replication_df = rt_replication(filename) %>% dplyr::select(!(article:pmid))
  )

  # Return dataframe of indicators
  out_ls %>%
    dplyr::bind_cols() %>%
    dplyr::select(article, pmid, tidyselect::everything())
}

Try the rtransparency package in your browser

Any scripts or data that you put into this service are public.

rtransparency documentation built on July 1, 2026, 9:07 a.m.