Learn R Programming

tools (version 3.6.2)

checkRdaFiles: Report on Details of Saved Images or Re-saves them

Description

This reports for each of the files produced by save the size, if it was saved in ASCII or XDR binary format, and if it was compressed (and if so in what format).

Usually such files have extension .rda or .RData, hence the name of the function.

Usage

checkRdaFiles(paths)
resaveRdaFiles(paths, compress = c("auto", "gzip", "bzip2", "xz"),
               compression_level, version = NULL)

Arguments

paths

A character vector of paths to save files. If this specifies a single directory, it is taken to refer to all .rda and .RData files in that directory.

compress, compression_level

Type and level of compression: see save. Values of compress can be abbreviated.

version

The format to be used when re-saving: see save.

Value

For checkRdaFiles, a data frame with rows names paths and columns

size

numeric: file size in bytes, NA if the file does not exist.

ASCII

logical: true for save(ASCII = TRUE), NA if the format is not that of an R save file.

compress

character: type of compression. One of "gzip", "bzip2", "xz", "none" or "unknown" (which means that if this is an R save file it is from a later version of R).

version

integer: the version of the save -- usually 2 but 1 for very old files, and NA for other files. Unfortunately 2 means ‘version 2 or later’.

Details

compress = "auto" asks R to choose the compression and ignores compression_level. It will try "gzip", "bzip2" and if the "gzip" compressed size is over 10Kb, "xz" and choose the smallest compressed file (but with a 10% bias towards "gzip"). This can be slow.

For back-compatibility, version = NULL is interpreted to mean version 2: however version-3 files will only be saved as version 3.

Examples

Run this code
# NOT RUN {
## from a package top-level source directory
paths <- sort(Sys.glob(c("data/*.rda", "data/*.RData")))
(res <- checkRdaFiles(paths))
## pick out some that may need attention
bad <- is.na(res$ASCII) | res$ASCII | (res$size > 1e4 & res$compress == "none")
res[bad, ]
# }

Run the code above in your browser using DataLab