compress.logs: Compress log files and optionally remove them

Description Usage Arguments Details Value Examples

View source: R/compress.logs.R

Description

Compress log files and optionally remove them to save space and make simulation results more portable

Usage

1
2
3
4
5
6
7
8
9
compress.logs(
  path.results = NULL,
  scenarios = "all",
  delete.log = TRUE,
  overwrite.gz = TRUE,
  compression = 7,
  parallel = FALSE,
  ncores = NULL
)

Arguments

path.results

The path to the 'Results' folder

scenarios

A character vector with the scenarios to be processed or "all"

delete.log

whether the log file should be deleted

overwrite.gz

if a .gz file with the same name is present, should it be overwritten?

compression

compression rate, integer between 0 and 9. See gzfile

parallel

whether execute the function in parallel

ncores

the number of cores if executed in parallel

Details

From (very limited) testing, a compression of 1 gives substantial compression (about 23% of original size) and it is very fast. compression=7 gives almost the max compression (~18.5% of the original size) taking ~ 4 times longer than compression=1. Anything beyon 7 takes much longer but with a gain of only a 0.1% or less.

Note that it makes sense to execute this function in parallel only if a solid state disk (SSD) is available. If ncores is left to its default (NULL) and parallel=TRUE all available processors will be used.

Value

a list where the first element is the list of log files found and the second is the gz files created

Examples

1
2
3
4
5
6
7
8
9
# Create a temp directory
tmp <- tempdir()
dir.create(file.path(tmp, "test"))
# Create a fake log file
cat(file=file.path(tmp, "test", "foo.log"), "Hello world!")
# Compress the log file
compress.logs(path.results=tmp, scenarios="test", delete.log=TRUE, overwrite.gz=TRUE)
# clean up
unlink(tmp, recursive=TRUE)

carlopacioni/HexSimR documentation built on Nov. 28, 2020, 4:12 p.m.