Chapter 7 Data types

All the basic data types and data structures provided by R are available in Rcpp. By using these data types, you can directly access the objects that exist in R.

7.1 Vector and Matrix

Following seven data types are often used in R.

logical integer numeric complex character Date POSIXct

There are vector type and matrix types in Rcpp corresponding to those of R.

In this document, the word Vector and Matrix is used to specify all the vector and matrix types in Rcpp.

The table below presents the correspondence of data types between R/Rcpp/C++.

Value R vector Rcpp vector Rcpp matrix Rcpp scalar C++ scalar
Logical logical LogicalVector LogicalMatrix - bool
Integer integer IntegerVector IntegerMatrix - int
Real numeric NumericVector NumericMatrix - double
Complex complex ComplexVector ComplexMatrix Rcomplex complex
String character CharacterVector (StringVector) CharacterMatrix (StringMatrix) String string
Date Date DateVector - Date -
Datetime POSIXct DatetimeVector - Datetime time_t

7.2 data.frame, list, S3, S4

Other than Vector and Matrix, There are several data structures in R such as data.frame, list, S3 class and S4 class. You can handle all of these data structures in Rcpp.

R Rcpp
data.frame DataFrame
list List
S3 class List
S4 class S4

In Rcpp, Vector, DataFrame, List are all implemented as kinds of vectors. Namely, Vector is a vector that its elements are scalar values, DataFrame is a vector that its elements are Vectors, List is a vector that its elements are any kind of data types. Thus, Vector, DataFrame, List has many common member functions in Rcpp.