Search code examples
rglobal-variables

R CMD CHECK "Found the following assignments to the global environment:"


Running R CMD check on my package I'm receiving the following warning message:

Found the following assignments to the global environment:
File ‘SciencesPo/R/describe.R’:
  assign(as.character(substitute(data)), dataset, pos = 1)

I tried to silence it by adding an environment as mentioned here using envir = .SciencesPoEnv, and envir = .GlobalEnv, but received the same message.

Does anyone have a clue how can I fix it?


Solution

  • This should do:

    #' function loading results in global environment
    #' @param pos defaults to 1 which equals an assingment to global environment
    assign_to_global <- function(pos=1){
      assign("sentence", "That was easy.", envir=as.environment(pos) )
    }