Teradata Package for R Function Reference | 17.00 - 17.00 - tdRetain - Teradata Package for R

Teradata® Package for R Function Reference

Teradata Package for R
Release Number
Release Date
July 2021
Content Type
Programming Reference
Publication ID
English (United States)


Retain option allows you to copy one or more columns into the final analytic data set. By default, the result column name is the same as the input column name, but this can be changed. If a specific type is specified, it results in casting the retained column.
The Retain transformation is supported for all valid data types.

  • The object of this class is passed to "retain" argument of td_transform_valib().


tdRetain(columns, datatype=NULL)



Required Argument.
Specifies name(s) of column(s) containing the input and output column names, where key is the name of the column to perform transformation on and value contains the name of the transformed output column. When only key is specified then output column name is the name of input column.
Types: character OR list of Strings (character)


Optional Argument.
Specifies the name of the intended datatype of the output column.
Intended data types for the output column can be specified using the permitted strings below:

------------------------------------ ---------------------------------------
If intended SQL Data Type is Permitted Value to be passed is
------------------------------------ ---------------------------------------
bigint bigint
byteint byteint
char(n) char,n
date date
decimal(m,n) decimal,m,n
float float
integer integer
number(*) number
number(n) number,n
number(*,n) number,*,n
number(n,n) number,n,n
smallint smallint
time(p) time,p
timestamp(p) timestamp,p
varchar(n) varchar,n


  1. Argument is ignored if "columns" argument is not used.

  2. char without a size is not supported.

  3. number(*) does not include the * in its datatype format.


  1. If intended datatype for the output column is 'bigint', then pass string 'bigint' to the argument as shown below:

  2. If intended datatype for the output column is 'decimal(3,5)', then pass string 'decimal,3,5' to the argument as shown below:

Types: character


An object of tdRetain class.


# 1. To run any transformation, user needs to use td_transform_valib()
#    function.
# 2. To do so set option 'val.install.location' to the database name
#    where Vantage analytic library functions are installed.
# 3. Datasets used in these examples can be loaded using Vantage Analytic
#    Library installer.

# Get the current context/connection
con <- td_get_context()$connection

# Set the option 'val.install.location'.
options(val.install.location = "SYSLIB")

# Create object(s) of class "tbl_teradata".
sales <- tbl(con, "sales")

# Example: Shows retaining some column unchanged and some with name or
#          datatype change.

# Retain columns 'accounts' and 'Feb' as is.
rt_1 <- tdRetain(columns=c("accounts", "Feb"))

# Retain column 'Jan' with name as 'january'.
rt_2 <- tdRetain(columns=list("Jan"="january"))

# Retain column 'Mar' and 'Apr' with name as 'march and 'april' with
# datatype changed to 'bigint'.
rt_3 <- tdRetain(columns=list("Mar"="march", "Apr"="april"),

# Perform the retain transformation using td_transform_valib() function.
obj <- td_transform_valib(data=sales, retain=c(rt_1, rt_2, rt_3))