roxyglobals icon indicating copy to clipboard operation
roxyglobals copied to clipboard

Generate utils::globalVariables() from roxygen tags

release lifecycle

roxyglobals

Generate `utils::globalVariables()` from roxygen @global tags.

Installation

remotes::install_github("anthonynorth/roxyglobals@*release")

Usage

Add roxyglobals to an R package DESCRIPTION via:

roxyglobals::use_roxyglobals()

Add @autoglobal to a function roxygen comment block, example:

#' Summarise responses
#'
#' @name summarise_responses
#' @param responses a data.frame of responses
#'
#' @autoglobal
#' @export
summarise_responses <- function(responses) {
  # station_name, station_type, end_time, start_time need to be added to 
  # utils::globalVariables() to keep R CMD CHECK happy
  responses %>%
    dplyr::group_by(station_name, station_type) %>%
    dplyr::summarise(
      count_responses = dplyr::n(),
      total_hours = sum(
        as.numeric(end_time - start_time, units = "hours"),
        na.rm = TRUE
      ),
      .groups = "drop"
    )
}

Or @global, example:

#' Summarise responses
#'
#' @name summarise_responses
#' @param responses a data.frame of responses
#'
#' @global station_name station_type end_time start_time
#' @export
summarise_responses <- function(responses) {
  # station_name, station_type, end_time, start_time need to be added to 
  # utils::globalVariables() to keep R CMD CHECK happy
  responses %>%
    dplyr::group_by(station_name, station_type) %>%
    dplyr::summarise(
      count_responses = dplyr::n(),
      total_hours = sum(
        as.numeric(end_time - start_time, units = "hours"),
        na.rm = TRUE
      ),
      .groups = "drop"
    )
}

Run devtools::document() to generate utils::globalVariables() in ./R/globals.R.

Example ./R/globals.R

# Generated by roxyglobals: do not edit by hand

utils::globalVariables(c(
  "end_time", # <summarise_responses>
  "start_time", # <summarise_responses>
  "station_name", # <summarise_responses>
  "station_type", # <summarise_responses>
  NULL
))