exportDataToSBDF
Export Data to an SBDF File

Description

Exports data to Spotfire's proprietary binary data format (SBDF).

Usage

exportDataToSBDF(data, file, rowNames = FALSE)

Arguments

data a data.frame or list object to export.
file a character string specifying the name of the Spotfire Binary Data File (SBDF) to create.
rowNames a logical flag. If rowNames=TRUE, the row names are exported to the data file.

Details

The following table shows the supported data types and how they are converted when you export from an R engine into SBDF.
R data type SBDF data type
logical Boolean
integer Integer (32 bit)
numeric Real
character String
factor String
POSIXct or POSIXlt DateTime
difftime TimeSpan
raw Binary
Most of the supported R data types are stored as data.frame columns containing atomic vectors. One exception is the raw data type, which is stored in a data.frame column as a list of raw objects and NULL values, such as data.frame(x=I(list(as.raw(1:3),as.raw(4:90),NULL))). The raw objects in such a list can have different lengths. Any elements of such a list that are not raw objects are exported as NULL.
Note: Spotfire Enterprise Runtime for R does not support the Spotfire data type Currency natively. Any Currency value contained in an SBDF file is imported to Spotfire Enterprise Runtime for R as numeric. If this numeric is then exported to an SDBF, it is converted to the Spotfire data type Real. This can result in a loss of precision for very large values.
SBDF does not support factors (categorical data types), so these are exported as simple strings.
It is possible to specify which SBDF data type to use for exporting each column (including types "Date" and "Time"), by giving data as a data.frame with an attribute "SBDFExportTypes". This attribute should be a named string vector associating column names with the desired exported SBDF data type for the column. This can be most easily set using the function setSBDFExportTypes. If a column name is not associated with an SBDF data type in "SBDFExportTypes", it is exported using the default types listed above.
The SBDF file format can represent a set of "data table properties" associated with the whole table, as well as a set of "column properties" values associated with each table column. Data table properties are represented in the data argument by adding a "SpotfireTableMetaData" attribute to the whole object. Column properties for an individual column are represented by adding a "SpotfireColumnMetaData" attribute to the column element of data. The value of a "SpotfireTableMetaData" or "SpotfireColumnMetaData" attribute should be a list of named elements, where each element can be one of the supported R data types that are listed above. Each list element must have length 1, except for raw data vectors, which can have any length.
Value
returns NULL.
See Also
importDataFromSBDF, setSBDFExportTypes
Examples
df <- data.frame(x=1:5, y=sin(1:5), z=LETTERS[1:5],
                 aa=I(lapply(1:5, function(i) as.raw(1:i))),
                 stringsAsFactors=FALSE)
## add a data table property
attr(df, "SpotfireTableMetaData") <- list(TMDInt=123L, TMDString="abc")
## add column properties to the 'x' column
attr(df[["x"]], "SpotfireColumnMetaData") <- list(CMDInt=345L, CMDString="def")
## Export the data to a temporary file:
tfile <- tempfile(fileext = ".sbdf")
exportDataToSBDF(df, tfile)
## Read the file in with importDataFromSBDF:
df2 <- importDataFromSBDF(tfile)
all.equal(df, df2)  ## two data objects are the same
## Clean up:
unlink(tfile)
Package SpotfireData version 6.1.1-7
Package Index