R/find_n_cores.R

Defines functions find_n_cores

Documented in find_n_cores

#' Cross platform helper to find number of cores
#'
#' @returns [int]
find_n_cores <- function(){
   if (.Platform$OS.type == "windows") {
      as.integer(Sys.getenv("NUMBER_OF_PROCESSORS"))
   } else if (Sys.info()[["sysname"]] == "Darwin") {  # macOS
      as.integer(system("sysctl -n hw.logicalcpu", intern = TRUE))
   } else {  # Assume Linux
      as.integer(system("nproc", intern = TRUE))
   }
}

Try the vmTools package in your browser

Any scripts or data that you put into this service are public.

vmTools documentation built on Aug. 8, 2025, 7:28 p.m.