R/check_mem_usage.R

Defines functions check_mem_usage

Documented in check_mem_usage

#' Check memory usage. Stop programm if memory usage is to hight.
#'
#' @param limit numeric. Define minimum free memory in MB
#'
#' @export
#'
#' @examples
#' check_mem_usage()
check_mem_usage <- function(limit = 2000){
  #check free memory
  if(.Platform$OS.type == "unix") {
    mem_free <- as.numeric(gsub(",",".",system("free | grep Mem | awk '{print $7 / 1000}'", intern = TRUE)))
  } else {
    # Default value
    mem_free <- limit + 1
  }
  #Stop programm if lot of memory is used
  if(mem_free > limit) {
    writeLines("Check memory usage : OK")
  } else {
    stop("Memory usage is to hight")
  }
}
naub1n/nnl documentation built on Nov. 19, 2020, 3:44 a.m.