setSBDFExportTypes
Access SBDF Data Types

### Description

Read or set the SBDF data types for columns imported or exported to Spotfire's proprietary binary data format (SBDF).

### Usage

    getSBDFImportTypes(df)
    setSBDFExportTypes(df, ...)

### Arguments

df | a data.frame that has been imported by importDataFromSBDF, or that is to be exported by exportDataToSBDF.
... | multiple arguments specifying which SBDF data type should be used for exporting columns. Each argument can be either a data.frame (whose desired data types are extracted via getSBDFImportTypes), or a named string vector, or a single string whose argument name gives the column name.

### Details

Spotfire's proprietary binary data format (SBDF) supports columns containing the following data types: Binary, Boolean, Currency, Date, DateTime, Integer, LongInteger, Real, SingleReal, String, Time, TimeSpan. Some of these types cannot be represented in an R engine, so they are converted when an SBDF file is read via importDataFromSBDF.
importDataFromSBDF stores the original SBDF data types for the input columns in the SBDFImportTypes attribute of the returned data.frame. This attribute, read via getSBDFImportTypes, is a named string vector associating each column name with the original SBDF data type. For example, it might be c(STR="String", TM="Time", LI="LongInteger") when reading three columns "STR", "TM", "LI" with SBDF types "String", "Time", and "LongInteger".
By default, exportDataToSBDF writes output columns with SBDF data types determined by the types of the R data columns. For example, a numeric column is written as an SBDF "Real" type, and a "POSIXct" column is written as an SBDF "DateTime" type. It is possible to specify the SBDF types to use for each column, by attaching an SBDFExportTypes attribute to the data.frame passed to exportDataToSBDF. This attribute value is a named string vector associating column names with SBDF types. For example, if this attribute had value c(AA="Integer", BB="Date"), then output column "AA" would be exported as SBDF type "Integer", and column "BB" would be exported as SBDF type "Date". If a column name doesn't appear, or its value is not an SBDF data type name, then the output column is exported using an SBDF type depends on the R column type.
Note: exportDataToSBDF cannot export all R data types to all SBDF data types. For example, it will produce an error if you attempt to export an R "numeric" column as a "DateTime" SBDF column. Also, it cannot export an SBDF "Currency" type: attempting to do this will export "Real" values instead.
The setSBDFExportTypes function makes it easier to construct and attach an appropriate SBDFExportTypes attribute to a data.frame. The attribute value is constructed from one or more ... arguments that each specify one or more column names and associated types. An argument may be one of (1) a data.frame, whose desired data types are extracted via getSBDFImportTypes, or (2) a named string vector, or (3) single string whose ... argument name gives the column name. Later arguments override earlier ones, so it is easy to modify one column specification. For example, setSBDFExportTypes(df,c(AA='Time',BB='Integer'), AA='DateTime') specifies column "AA" with SBDF type "DateTime", and column "BB" with type "Integer" (and any other columns with default types).
Because the export types are specified by the SBDFExportTypes attribute, rather than as an argument to exportDataToSBDF, this allows specifying the types in Spotfire data functions, where scripts create output values without explicitly calling exportDataToSBDF. Often one wants to export output columns with the same SBDF types as input columns with the same names, which is possible to do via code such as output<-setSBDFExportTypes(calc.output(input),input).
Value
getSBDFImportTypes returns the named string vector giving the imported column names and the associated SBDF data types.
setSBDFExportTypes returns df with an added SBDFExportTypes attribute specifying the SBDF data types to use for exporting the columns.
See Also
importDataFromSBDF, exportDataToSBDF
Examples

    df <- data.frame(x=1:5, y=sin(1:5), z=LETTERS[1:5],
                     a=as.POSIXct(1:5, origin = "1970-01-01", tz = "UTC"),
                     stringsAsFactors=FALSE)
    ## specify output SBDF data types for some columns
    df <- setSBDFExportTypes(df,
       c(x="LongInteger", y="SingleReal", a="Time"), y="Real")
    ## Export the data to a temporary file:
    tfile <- tempfile(fileext = ".sbdf")
    exportDataToSBDF(df, tfile)
    ## Read the file with importDataFromSBDF:
    df2 <- importDataFromSBDF(tfile)
    getSBDFImportTypes(df2)
    ## returns: c(x="LongInteger", y="Real", z="String", a="Time")
    ## Clean up:
    unlink(tfile)

Package SpotfireData version 6.1.5-18
Package Index