R/utils_server.R

Defines functions getAvailMem logical_to_ok_issue

# logical_to_character_icon <- function(x){
#   dplyr::if_else(x == TRUE,
#                  as.character(icon("ok-sign", lib = "glyphicon")),
#                  as.character(icon("exclamation-sign", lib = "glyphicon"))
#   )
# }
# 
# logical_to_good_bad <- function(x){
#   dplyr::if_else(x == TRUE,
#                  "GOOD",
#                  "BAD")
#   
# }

logical_to_ok_issue <- function(x){
  dplyr::if_else(x == TRUE,
                 "OK",
                 "Issue")
  
}

getAvailMem <- function(format = TRUE) {
  
  gc()
  
  if (Sys.info()[["sysname"]] == "Windows") {
    memfree <- 1024^2 * (utils::memory.limit() - utils::memory.size())
  } else {
    # http://stackoverflow.com/a/6457769/6103040
    memfree <- 1024 * as.numeric(
      system("awk '/MemFree/ {print $2}' /proc/meminfo", intern = TRUE))
  }
  
  `if`(format, format(structure(memfree, class = "object_size"),
                      units = "auto"), memfree)
}
bcgov/GWELLS-QAQC-RShiny-Dashboard documentation built on Oct. 18, 2022, 1:48 p.m.