rds2cpp
Read and write RDS/RDA files in C++
Loading...
Searching...
No Matches
rds2cpp Namespace Reference

Parse an RDS file in C++. More...

Classes

struct  AtomicVector
 Vector of some atomic type. More...
 
struct  Attribute
 Attribute name and value. More...
 
struct  BuiltInFunction
 Built-in function. More...
 
struct  Environment
 An R environment. More...
 
struct  EnvironmentIndex
 Reference to an environment. More...
 
struct  EnvironmentVariable
 Variable in an Environment. More...
 
struct  ExpressionVector
 Expression vector. More...
 
struct  ExternalPointer
 An R external pointer. More...
 
struct  ExternalPointerIndex
 Reference to an external pointer. More...
 
struct  GenericVector
 Generic vector, i.e., an ordinary R list. More...
 
struct  LanguageArgument
 Function argument in a LanguageObject. More...
 
struct  LanguageObject
 Language object, i.e., a function call. More...
 
struct  Null
 R's NULL value. More...
 
struct  PairList
 Pairlist, i.e., a linked list. More...
 
struct  PairListElement
 Element of a PairList. More...
 
struct  ParseRdaOptions
 Options for parse_rda(). More...
 
struct  ParseRdsOptions
 Options for parse_rds(). More...
 
struct  RdaFile
 Contents of the parsed RDA file. More...
 
struct  RdaObject
 R object saved in a RdaFile. More...
 
struct  RdsFile
 Contents of the parsed RDS file. More...
 
struct  RObject
 Virtual class for all unserialized R objects. More...
 
struct  S4Object
 S4 object. More...
 
struct  String
 Single string in a StringVector. More...
 
struct  StringVector
 String vector. More...
 
struct  Symbol
 An R symbol. More...
 
struct  SymbolIndex
 Reference to a language symbol. More...
 
struct  Version
 Major-minor-patch version number, usually of R itself. More...
 
struct  WriteRdaOptions
 Options for write_rda(). More...
 
struct  WriteRdsOptions
 Options for write_rds(). More...
 

Typedefs

typedef AtomicVector< std::int32_t, SEXPType::INT > IntegerVector
 Integer vector.
 
typedef AtomicVector< std::int32_t, SEXPType::LGL > LogicalVector
 Logical vector.
 
typedef AtomicVector< double, SEXPType::REAL > DoubleVector
 Double-precision vector.
 
typedef AtomicVector< unsigned char, SEXPType::RAW > RawVector
 Raw vector.
 
typedef AtomicVector< std::complex< double >, SEXPType::CPLX > ComplexVector
 Complex vector.
 
typedef RdsFile Parsed
 

Enumerations

enum class  StringEncoding : unsigned char { NONE , LATIN1 , UTF8 , ASCII }
 
enum class  SEXPType : unsigned char {
  NIL = 0 , SYM = 1 , LIST = 2 , CLO = 3 ,
  ENV = 4 , PROM = 5 , LANG = 6 , SPECIAL = 7 ,
  BUILTIN = 8 , CHAR = 9 , LGL = 10 , INT = 13 ,
  REAL = 14 , CPLX = 15 , STR = 16 , DOT = 17 ,
  ANY = 18 , VEC = 19 , EXPR = 20 , BCODE = 21 ,
  EXTPTR = 22 , WEAKREF = 23 , RAW = 24 , S4 = 25 ,
  REF = 255 , NILVALUE_ = 254 , GLOBALENV_ = 253 , UNBOUNDVALUE_ = 252 ,
  MISSINGARG_ = 251 , BASENAMESPACE_ = 250 , NAMESPACE = 249 , PACKAGE = 248 ,
  PERSIST = 247 , CLASSREF = 246 , GENERICREF = 245 , BCREPDEF = 244 ,
  BCREPREF = 243 , EMPTYENV_ = 242 , BASEENV_ = 241 , ATTRLANG = 240 ,
  ATTRLIST = 239 , ALTREP_ = 238
}
 

Functions

SymbolIndex register_symbol (std::string name, StringEncoding encoding, std::vector< Symbol > &symbols)
 
template<class Reader_ >
RdsFile parse_rds (Reader_ &reader, const ParseRdsOptions &options)
 
RdsFile parse_rds (std::string file, const ParseRdsOptions &options)
 
template<class Writer >
void write_rds (const RdsFile &info, Writer &writer, const WriteRdsOptions &options)
 
void write_rds (const RdsFile &info, const char *path, const WriteRdsOptions &options)
 
void write_rds (const RdsFile &info, std::string path, const WriteRdsOptions &options)
 
template<class Reader_ >
RdaFile parse_rda (Reader_ &reader, const ParseRdaOptions &options)
 
RdaFile parse_rda (std::string file, const ParseRdaOptions &options)
 
template<class Writer >
void write_rda (const RdaFile &info, Writer &writer, const WriteRdaOptions &options)
 
void write_rda (const RdaFile &info, const char *path, const WriteRdaOptions &options)
 
void write_rda (const RdaFile &info, std::string path, const WriteRdaOptions &options)
 

Detailed Description

Parse an RDS file in C++.

Typedef Documentation

◆ Parsed

Typedef for back-compatibility.

Enumeration Type Documentation

◆ SEXPType

enum class rds2cpp::SEXPType : unsigned char
strong

Data types within R.

Values from 0 to 25 were taken from the R internals documentation. Of particular interest are the following:

  • NIL is R's NULL.
  • ENV is an R environment.
  • LGL is a logical vector.
  • INT is an integer vector.
  • REAL is a double vector.
  • CPLX is a complex vector.
  • STR is a string vector (also known as a character vector in R). Do not confuse this with CHAR, which refers to an internal representation of a single string.
  • VEC is an ordinary R list. Do not confuse this with LIST, which refers to a pairlist.

Values from 238 to 255 were determined by inspecting the R source code.

◆ StringEncoding

enum class rds2cpp::StringEncoding : unsigned char
strong

Encoding options for R strings.

Function Documentation

◆ parse_rda() [1/2]

template<class Reader_ >
RdaFile rds2cpp::parse_rda ( Reader_ & reader,
const ParseRdaOptions & options )

Parse the contents of an RDA file.

Template Parameters
Reader_A byteme::Reader class, or any class with a compatible interface.
Parameters
readerInstance of a Reader class, containing the contents of the RDA file.
optionsFurther options for parsing.
Returns
An RdaFile object containing the contents of the RDA file.

◆ parse_rda() [2/2]

RdaFile rds2cpp::parse_rda ( std::string file,
const ParseRdaOptions & options )
inline

Parse the contents of a Gzip-compressed RDA file.

Parameters
filePath to a Gzip-compressed RDA file.
optionsFurther options for parsing.
Returns
An RdaFile object containing the contents of file.

◆ parse_rds() [1/2]

template<class Reader_ >
RdsFile rds2cpp::parse_rds ( Reader_ & reader,
const ParseRdsOptions & options )

Parse the contents of an RDS file.

Template Parameters
Reader_A byteme::Reader class, or any class with a compatible interface.
Parameters
readerInstance of a Reader class, containing the contents of the RDS file.
optionsFurther options for parsing.
Returns
An RdsFile object containing the contents of the RDS file.

◆ parse_rds() [2/2]

RdsFile rds2cpp::parse_rds ( std::string file,
const ParseRdsOptions & options )
inline

Parse the contents of a Gzip-compressed RDS file.

Parameters
filePath to a Gzip-compressed RDS file.
optionsFurther options for parsing.
Returns
An RdsFile object containing the contents of file.

◆ register_symbol()

SymbolIndex rds2cpp::register_symbol ( std::string name,
StringEncoding encoding,
std::vector< Symbol > & symbols )
inline
Parameters
nameName of the symbol, see Symbol::name.
encodingEncoding of the symbol, see Symbol::encoding.
symbolsVector containing the global set of symbols, typically RdsFile::symbols or RdaFile::symbols.
Returns
A new symbol is added to symbols and a SymbolIndex is returned that points to the new entry of symbols.

This is a convenient helper to register new symbols in RdsFile prior to calling write_rds() (or to RdaFile before write_rda()). It returns a SymbolIndex that can be used in various fields like LanguageArgument::name, PairListElement::tag, EnvironmentVariable::name, etc. For efficiency, users can re-use the same SymbolIndex in multiple locations within the same RdsFile and RdaFile to reference this combination of name and encoding. However, it is perfectly fine to create a new SymbolIndex in such cases as any duplicated combinations will be automatically removed by write_rds() and write_rda().

◆ write_rda() [1/3]

void rds2cpp::write_rda ( const RdaFile & info,
const char * path,
const WriteRdaOptions & options )
inline

Write an R object to a Gzip-compressed RDA file.

Parameters
infoInformation about the RDA file to be written, including a pointer to a valid RObject.
pathPath to the output file.
optionsFurther options.

◆ write_rda() [2/3]

void rds2cpp::write_rda ( const RdaFile & info,
std::string path,
const WriteRdaOptions & options )
inline

Write an R object to a Gzip-compressed RDA file.

Parameters
infoInformation about the RDA file to be written, including a pointer to a valid RObject.
pathPath to the output file.
optionsFurther options.

◆ write_rda() [3/3]

template<class Writer >
void rds2cpp::write_rda ( const RdaFile & info,
Writer & writer,
const WriteRdaOptions & options )

Convert an R object into the RDA format and write it to a specified output.

Template Parameters
WriterA byteme::Writer class, or any class with a compatible interface.
Parameters
infoInformation about the RDA file to be written, including a pointer to a valid RObject.
writerInstance of a Writer class, where the RDA file is to be written.
optionsFurther options.

◆ write_rds() [1/3]

void rds2cpp::write_rds ( const RdsFile & info,
const char * path,
const WriteRdsOptions & options )
inline

Write an R object to a Gzip-compressed RDS file.

Parameters
infoInformation about the RDS file to be written, including a pointer to a valid RObject.
pathPath to the output file.
optionsFurther options.

◆ write_rds() [2/3]

void rds2cpp::write_rds ( const RdsFile & info,
std::string path,
const WriteRdsOptions & options )
inline

Write an R object to a Gzip-compressed RDS file.

Parameters
infoInformation about the RDS file to be written, including a pointer to a valid RObject.
pathPath to the output file.
optionsFurther options.

◆ write_rds() [3/3]

template<class Writer >
void rds2cpp::write_rds ( const RdsFile & info,
Writer & writer,
const WriteRdsOptions & options )

Convert an R object into the RDS format and write it to a specified output.

Template Parameters
WriterA byteme::Writer class, or any class with a compatible interface.
Parameters
infoInformation about the RDS file to be written, including a pointer to a valid RObject.
writerInstance of a Writer class, where the RDS file is to be written.
optionsFurther options.