R/inv_gc.R

Defines functions inv_gc

Documented in inv_gc

#' Run invisible garbage collection
#'
#' @description
#' Run garbage collection without the `gc()` output. Can also be run in the middle of a long pipe chain. Useful for large datasets.
#'
#' @param .data Optional. If null runs `gc()` silently. Else returns the same object unaltered.
#' @export
#'
#' @examples
#' inv_gc()
#'
#' df %>%
#'   inv_gc() %>%
#'   select(col1, col2)
inv_gc <- function(.data = NULL) {
  if(missing(.data)) {
    invisible(gc())
  } else {
    invisible(gc())
    return(.data)
  }
}
mtfairbanks/gts documentation built on Feb. 12, 2020, 1:22 p.m.