loc.gov

Description

The RData format (usually with extension .rdata or .rda) is a format designed for use with R, a system for statistical computation and related graphics, for storing a complete R workspace or selected "objects" from a workspace in a form that can be loaded back by R. The save function in R has options that result in significantly different variants of the format. This description is for the family of formats created by save and closely related functions. A workspace in R is a collection of typed "objects" and may include much more than the typical tabular data that might be considered a "dataset," including, for example, results of intermediate calculations and scripts in the R programming language. A workspace may also contain several datasets, which are termed "data frames" in R. See Notes below for more on the object-oriented terminology used in R and its documentation, particularly in relation to the data that might be in an RData file.

The R system consists of a special-purpose object-oriented programming language designed for statistical analysis and visualization, together with a run-time environment for its use. The runtime environment has the ability to interpret individual commands and run programs in R code, stored as text. The R software is released as open source under the GNU General Public License (GPL), version 2 and is in continuous active development under the auspices of the R Foundation. R was originally developed at the Department of Statistics of the University of Auckland in New Zealand. Since mid-1997 the software has been extended and modified by the "R Core Team," a group of individuals that includes the original authors of R, and a predecessor language called S. See What is R? and Wikipedia entry on R (programming language). Implementations of the R system exist for many Unix variants, MacOS, and Windows. The R Base Package has the ability to install extension packages for additional analysis or data manipulation tasks. The Comprehensive R Archive Network (CRAN) is the official source for R software and, as of mid-2017, lists over 10,000 packages.

RData format subtypes/options: Although the files usually use the same extension, there are several distinct variations that are commonly found, because the save function offers options.

The main options are:

  • Between ASCII, binary, or XDR data representations: These can be distinguished by the first few bytes of the file. The top-level header consists of 4 bytes followed by hex "0A" (LF, linefeed). This functions as a magic number. A secondary header begins the actual serialization of objects and consists of a single byte (with ASCII value "A", "B", or "X" as legal options) followed by another hex "0A" (LF, linefeed).
    • A -- ASCII representation: Each item of information (number or text string) is written out on a separate line, terminated by hex "0A" (LF, linefeed). This results in a file that can be opened in many text editors, but is much more cryptic than a CSV file, for example. A small file with annotated listing is available at a blog post on the The RData File Format. As usual, when internal binary floating point numbers are converted to character data, there is potential for loss of precision. Note that even when saved as ASCII, RData files must be treated as binary files, to ensure that they are transferred without conversion of end-of-line markers and of 8-bit characters.
    • B -- a deprecated binary representation: This was used for the word-order binary native to the local operating system. Option X is now recommended instead, with the aim of platform-independence.
    • X -- big-endian (XDR) binary representation: The default representation for RData files. Integers and floating point numbers in these files are compatible with the C programming language. A hex dump of such files reveals any ASCII character data and names of objects.
  • Whether or not compression is applied: The default is for compression using Gzip. Other compression algorithms are supported within the R system, and it is also possible to vary compression parameters. The file that is compressed may use the XDR or ASCII representations (and presumably the deprecated local binary representation). The Gzip-compressed file will have the magic number that identifies a Gzip file (usual file extension .gz).

Based on serialize.c, the source code that writes the saved files, the content (typed objects and their component items) is serialized in the same order for all variants. The most commonly occurring variants in active use seem likely to be compressed XDR and compressed or uncompressed ASCII. R documentation states, "ASCII saves used to be useful for moving data between platforms but are now mainly of historical interest." However, documentation for the commercial Stat/Transfer data conversion utility on RData files states it supports the binary or ASCII format, compressed files, and the newer Version 3 serialization format.

RData file organization: RData files are organized as a sequence of objects. Each object has a type, coded as an integer, and each object type comprises certain sub-objects and items in a prescribed order. A data frame object typically has a set of typed vectors, one vector per variable. The general (if somewhat simplified) form for each vector will start with the code for its vector type (numeric, logical, character, etc.), followed by a text string object for its name, a count of elements/rows, and finally the element values.

New object types can be introduced by installing packages beyond the R Base Package and by code written specifically for analysis of a certain collection of data. Hence, many RData files cannot be fully understood or used without access to R extension packages and/or their documentation.

Read the original on loc.gov ↗