Data Exchange Details

The IMLPlus language and the R language have significant differences in the areas of data types and data structures. This topic describes how IML Studio reconciles these differences. Note that when transferring data from R to IMLPlus, IML Studio performs all the relevant conversion steps described in this topic regardless of whether the destination is a SAS data set or an IML matrix.

Numeric Data Types

R can store numeric data in either integer format or double precision format. IMLPlus stores all numeric matrices in double precision format. The IMLPlus DataObject class also stores all numeric data in double precision format. When IML Studio transfers numeric data from R to IMLPlus, it converts any integer data to double precision format.

Nominal Numeric Data

Each variable in an IMLPlus DataObject is assigned a measurement level. The measurement level for a numeric variable can be either Interval or Nominal. R does not have the concept of a measurement level for numeric data, but R has factors. When IML Studio transfers a nominal numeric variable from IMLPlus to R, it creates a factor in R. When IML Studio transfers data from R to IMLPlus, it performs the following steps for each variable to convert factors appropriately:

  1. Determine whether the variable is a factor.
  2. If the variable is a factor, perform the following steps:
    1. If the variable's non-missing data consists entirely of numbers (in text form), create a nominal numeric variable in IMLPlus.
    2. Otherwise, create a character variable in IMLPlus.
Logical Data

R provides a data type called logical for storing the values TRUE and FALSE. When IML Studio transfers logical data to IMLPlus, it converts the value TRUE to the number 1 and the value FALSE to the number 0.

Character Data

IML Studio stores character data internally in Unicode UTF-16 format. When IML Studio transfers character data from IMLPlus to R, it performs the following steps:

  1. IML Studio transcodes the data from UTF-16 to the encoding being used by R. If the transcoding cannot be performed, IML Studio will display an error message.
  2. If the R option stringsAsFactors is TRUE when the data transfer occurs, IML Studio creates a factor in R. Otherwise, IML Studio creates a character vector.

When IML Studio transfers character data from R to IMLPlus, it performs the following steps:

  1. IML Studio transcodes the data from the encoding being used by R to UTF-16. This transcoding should always succeed.
  2. If the R variable is a factor and the variable's non-missing data consists entirely of numbers (in text form), IML Studio creates a nominal numeric variable in IMLPlus. Otherwise, IML Studio creates a character variable in IMLPlus.
Unsupported Data Types

R provides two data types that are not supported by the IML Studio interface to R: complex, and raw. IMLPlus does not support either of these data types. If you attempt to transfer data stored in either of these data types to IMLPlus, IML Studio will display an error message.

Special Numeric Values

R supports special numeric values such as infinities and NaNs differently from IMLPlus. For information about how IMLPlus and SAS support special numeric values, please refer to the topic About Infinities and NaNs.

The following table shows how IML Studio converts SAS missing values when transferring data from IMLPlus to R:

SAS Missing Value Value in R
.I Inf
.M -Inf
all others NA

The following table shows how IML Studio converts special numeric values when transferring data from R to IMLPlus:

Value in R SAS Missing Value
Inf .I
-Inf .M
NA .
NaN .
Dates, Times, and Datetimes

R supports date and time data differently from IMLPlus. In IMLPlus (and SAS in general), variables are not explicitly tagged as containing date or time data. Instead, such variables are assigned a format (such as DATE9.) that causes the numeric values to be displayed in the desired format. In R, variables are explicitly tagged as containing date or time data. When IML Studio transfers data from IMLPlus to R, it performs the following steps for each variable to convert date and time data:

  1. Examine the format assigned to the variable.
  2. If the variable's format is in the family of date formats (e.g. DATE.), assign the "Date" class to the variable in R.
  3. If the variable's format is in the family of datetime formats (e.g. DATETIME.), assign the classes "POSIXt" and "POSIXct" to the variable in R.
  4. If the variable's format is in the family of time formats (e.g. TIME.), assign the classes "POSIXt" and "POSIXct" to the variable in R.
  5. In all other cases, assign the "numeric" class to the variable in R.

When IML Studio transfers data from R to IMLPlus, it performs the following steps for each variable to convert date and time data:

  1. Examine the class of the variable.
  2. If the variable's class is "Date", assign the format "DATE9." to the variable in IMLPlus.
  3. If the variable's class is "POSIXt", assign the format "DATETIME19." to the variable in IMLPlus.
  4. In all other cases, don't assign a format to the variable in IMLPlus.
Time Series Data

In IMLPlus (and SAS in general), the sampling times for time series data are stored in a separate variable. In R, the sampling times for time series data are specified by the tsp attribute of a time series variable. When IML Studio transfers data from R to IMLPlus, it performs the following steps for each variable to preserve the sampling times:

  1. Determine whether the variable has a tsp attribute.
  2. If the variable has a tsp attribute, perform the following steps:
    1. Use the R function time to generate a vector of the times at which the time series was sampled.
    2. Create a new variable named "VarName_ts", where VarName is the name of the R variable.
    3. Set the sampling time vector as the data for the new variable.

The following IMLPlus program demonstrates how to use time series data imported from R:

declare DataObject dobj = DataObject.CreateFromR( "co2", "co2" );
DataTable.Create( dobj ).SetWindowPosition( 50, 50 );

declare LinePlot plot = LinePlot.Create( dobj, "x_ts", "x" );
plot.ShowPoints( "x", false );

When IML Studio transfers data from IMLPlus to R, it does not perform any special processing related to time series.

Data Structures

R provides a wider range of data structures than IMLPlus (excluding the ability of IMLPlus to use Java data structures and objects). To package all R data into a data structure that is compatible with IMLPlus, IML Studio transfers all data from R to IMLPlus using R data frames. If the R data is not already in the form of a data frame, IML Studio coerces the data to a data frame before transferring it to IMLPlus.