R/updateBlocksize.R

Defines functions updateBlocksize

Documented in updateBlocksize

updateBlocksize = function(blocksize=c(), bsc_qc=data.frame(time=c(),size=c())) {
  if (length(blocksize) == 0) {
    cat("\nWarning: Please provide valid blocksize unequal to zero")
  }
  gco = gc()
  memuse = gco[2,2] #memuse in mb
  bsc_qc_new_row = data.frame(time=format(Sys.time()),size=memuse,stringsAsFactors = FALSE)
  if (nrow(bsc_qc) == 0) {
    bsc_qc = bsc_qc_new_row
  } else {
    bsc_qc = rbind(bsc_qc,bsc_qc_new_row)
  }
  if (memuse > 4000) {
    if (nrow(bsc_qc) < 5) {
      blocksize = round(blocksize * 0.8)
    }
  }
  # Following commented out because it causes problems with reproducibility in unit-test across machines:
  # assumed_memory_R = 4000
  # memratio = (assumed_memory_R - memuse) / memuse
  # if (nrow(bsc_qc) < 10) {
  #   if (memratio > 1.1) {
  #     blocksize = round(blocksize * 0.8) # reduce blocksize
      # } else if (memratio < 0.90) {  # increase blocksize.... 
      #   blocksize = round(blocksize * 1.1) 
  #   }
  # }
  blocksize = round(blocksize)
  return(list(blocksize=blocksize, bsc_qc=bsc_qc))
}

Try the GGIR package in your browser

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

GGIR documentation built on Oct. 17, 2023, 1:12 a.m.