https://github.com/anthonynorth/roxyglobals
  
  
    Generate utils::globalVariables() from roxygen tags 
    https://github.com/anthonynorth/roxyglobals
  
roxygen2
        Last synced: 3 months ago 
        JSON representation
    
Generate utils::globalVariables() from roxygen tags
- Host: GitHub
 - URL: https://github.com/anthonynorth/roxyglobals
 - Owner: anthonynorth
 - License: other
 - Created: 2020-09-09T07:31:20.000Z (about 5 years ago)
 - Default Branch: master
 - Last Pushed: 2023-08-22T00:08:03.000Z (about 2 years ago)
 - Last Synced: 2025-06-15T16:00:35.361Z (5 months ago)
 - Topics: roxygen2
 - Language: R
 - Homepage:
 - Size: 86.9 KB
 - Stars: 52
 - Watchers: 1
 - Forks: 0
 - Open Issues: 1
 - 
            Metadata Files:
            
- Readme: README.md
 - Changelog: NEWS.md
 - License: LICENSE
 
 
Awesome Lists containing this project
- jimsghstars - anthonynorth/roxyglobals - Generate utils::globalVariables() from roxygen tags (R)
 - awesome-r-pkgtools - `{roxyglobals}`
 
README
          # roxyglobals
[](https://github.com/anthonynorth/roxyglobals/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/anthonynorth/roxyglobals?branch=master)
[](https://CRAN.R-project.org/package=roxyglobals)
[](https://anthonynorth.r-universe.dev/roxyglobals)
[](https://github.com/anthonynorth/roxyglobals)
Generate `utils::globalVariables()` from roxygen @autoglobal and @global tags.
## Installation
```r
# 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:
```r
# 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:
```r
# 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:
```r
#' 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:
```r
#' 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:
```r
# Generated by roxyglobals: do not edit by hand
utils::globalVariables(c(
  "end_time", # 
  "start_time", # 
  "station_name", # 
  "station_type", # 
  NULL
))
```