roxyglobals icon indicating copy to clipboard operation
roxyglobals copied to clipboard

`@autoglobal` does not record `.` in `globals.R`

Open joshwlambert opened this issue 10 months ago • 1 comments

Thanks for developing this great package!

I'm using @autoglobal in a package that uses {data.table}. {data.table} syntax allows list() to be replaced with .(), which is detected by R CMD check (devtools::check()) as:

checking R code for possible problems ... NOTE
  foo: no visible global function definition for ‘.’
  Undefined global functions or variables:
    .

Here is an example function that would produce this check note:

#' Subset a `<data.table>`
#'
#' @param x A `<data.table>` including columns `$a` and `$b`.
#'
#' @return A `<data.table>`
#' @autoglobal
#' @export
#'
#' @examples
#' if (requireNamespace("data.table", quietly = TRUE)) {
#'   dt <- data.table::data.table(a = 1:10, b = 11:20, c = letters[1:10])
#'   foo(x = dt)
#' }
foo <- function(x) {
  x[, .(a, b)]
}

It would be great if @autoglobal could also add . to the globals.R file.

joshwlambert avatar Mar 04 '25 11:03 joshwlambert

Roxyglobals ignores function calls when detecting globals. That said, it's probably safe to include .() along with dplyr's :=

https://github.com/anthonynorth/roxyglobals/blob/ab29bdcd2e618fbfd91356fc22095e961b48333d/R/extract.R#L11

anthonynorth avatar Nov 20 '25 23:11 anthonynorth