'Roxygen2' Global Variable Declarations

Generate utils::globalVariables() from 'roxygen2' @global and @autoglobal tags.


roxyglobals

R-CMD-check Codecov test coverage CRAN r-universe latest

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

Installation

# Install the released version from CRAN
install.packages("roxyglobals")

# Install the released version from r-universe
install.packages("roxyglobals", repos = "https://anthonynorth.r-universe.dev")

# Or the development version from GitHub:
# install.packages("remotes")
remotes::install_github("anthonynorth/roxyglobals")

Setup

Add roxyglobals to an R package DESCRIPTION via:

# Add to current R package
roxyglobals::use_roxyglobals()

# Or add to another R package
# install.packages("withr")
withr::with_dir("path/to/package", roxyglobals::use_roxyglobals())

Config

By default, roxyglobals writes all discovered globals (including duplicates) to R/globals.R. You may configure the filename and global generation behaviour with:

# write globals to R/generated-globals.R
roxyglobals::options_set_filename("generated-globals.R")

# only emit unique globals
roxyglobals::options_set_unique(TRUE)

Usage

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 your globals file (default R/globals.R). Example globals file:

# 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
))

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("roxyglobals")

1.0.0 by Anthony North, 3 years ago


https://github.com/anthonynorth/roxyglobals


Report a bug at https://github.com/anthonynorth/roxyglobals/issues


Browse source code at https://github.com/cran/roxyglobals


Authors: Anthony North [aut, cre, cph] , Miles McBain [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports brio, codetools, desc, roxygen2

Suggests covr, testthat, withr


Suggested by ABCDscores, ECDFniche, GSODR, SPIChanges, TCRconvertR, caretSDM, contactsurveys, cvasi, distantia, epidist, getCRUCLdata, hagis, hestia, imuGAP, read.abares, ringbp, scShardSplitRef, sixtyfour, socialmixr, weatherOz.


See at CRAN