Teradata Package for R Function Reference | 17.00 - tdRetain - Teradata Package for R - Look here for syntax, methods and examples for the functions included in the Teradata Package for R.

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
Retain

Description

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.
Note:

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

Usage

tdRetain(columns, datatype=NULL)

Arguments

columns

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)

datatype

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

Notes:

  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.

Examples:

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

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

Types: character

Value

An object of tdRetain class.

Examples


Notes:
# 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")
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"),
                 datatype="bigint")

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