Teradata Package for R Function Reference | 17.20 - StrApply - 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

Deployment
VantageCloud
VantageCore
Edition
Enterprise
IntelliFlex
VMware
Product
Teradata Package for R
Release Number
17.20
Published
March 2024
ft:locale
en-US
ft:lastEdition
2024-05-03
dita:id
TeradataR_FxRef_Enterprise_1720
lifecycle
latest
Product Category
Teradata Vantage

StrApply

Description

td_str_apply_sqle() function applies a specified string operator to the specified input tbl_teradata columns.

Usage

  td_str_apply_sqle (
      data = NULL,
      target.columns = NULL,
      output.columns = NULL,
      accumulate = NULL,
      string.operation = NULL,
      operating.side = NULL,
      in.place = TRUE,
      string = NULL,
      escape.string = NULL,
      is.case.specific = TRUE,
      ignore.trailing.blank = FALSE,
      string.length = NULL,
      start.index = NULL,
      ...
  )

Arguments

data

Required Argument.
Specifies the input tbl_teradata.
Types: tbl_teradata

target.columns

Required Argument.
Specifies the name(s) of the column(s) in "data" to perform string operations on.
Types: character OR vector of Strings (character)

output.columns

Optional Argument.
Specifies the output column names that contains the output of the string operation on the columns values.
Types: character OR vector Strings (character)

accumulate

Optional Argument.
Specifies the names of input tbl_teradata columns to copy to the output.
Types: character OR vector of Strings (character)

string.operation

Required Argument.
Specifies the string method to use on the target columns.
Permitted Values:

  • TOUPPER

  • TOLOWER

  • strTRIM

  • strCON

  • strPAD

  • strLIKE

  • strINDEX

  • INITCAP

  • TRIMSPACES

  • CHARTOHEXINT

  • strREVERSE

  • SUBstr

  • GETNCHARS

  • UNICODEstr

Types: character

operating.side

Optional Argument.
Specifies the operating side to consider while performing operations like 'stringPad', 'getNchars'.
Permitted Values: LEFT, RIGHT
Default Value: LEFT
Types: character

in.place

Optional Argument.
Specifies whether to use the same column name for the resulted target columns.
Default Value: TRUE
Types: logical

string

Optional Argument.
Specifies the names of the strings to use as input while applying string operation.
Types: character OR vector of Strings (character)

escape.string

Optional Argument.
Specifies the names of the string to use as an escape string while applying stringLike operation.
Types: character OR vector of Strings (character)

is.case.specific

Optional Argument.
Specifies whether to consider uppercase letters(e.g. "A") and lowercase letters(e.g. "a") as same or different.
Default Value: TRUE
Types: logical

ignore.trailing.blank

Optional Argument.
Specifies whether to ignore trailing blanks in the column strings. Used if the stringOperation is 'StringLike' only.
Default Value: FALSE
Types: logical

string.length

Optional Argument.
Specifies the length of a string.
Types: integer

start.index

Optional Argument.
Specifies the start index of the target column string. Used only if the string operation is 'SubString'.
Types: integer

...

Specifies the generic keyword arguments SQLE functions accept.
Below are the generic keyword arguments:

persist:
Optional Argument.
Specifies whether to persist the results of the function in a table or not.
When set to TRUE, results are persisted in a table; otherwise, results are garbage collected at the end of the session.
Default Value: FALSE
Types: logical

volatile:
Optional Argument.
Specifies whether to put the results of the function in a volatile table or not.
When set to TRUE, results are stored in a volatile table, otherwise not.
Default Value: FALSE
Types: logical

Function allows the user to partition, hash, order or local order the input data. These generic arguments are available for each argument that accepts tbl_teradata as input and can be accessed as:

  • "<input.data.arg.name>.partition.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.hash.column" accepts character OR vector of Strings (character) (Strings)

  • "<input.data.arg.name>.order.column" accepts character OR vector of Strings (character) (Strings)

  • "local.order.<input.data.arg.name>" accepts logical

Note:
These generic arguments are supported by tdplyr if the underlying SQL Engine function supports it, else an exception is raised.

Value

Function returns an object of class "td_str_apply_sqle" which is a named list containing object of class "tbl_teradata".
Named list member(s) can be referenced directly with the "$" operator using the name(s):result

Examples

  
    
    # Get the current context/connection.
    con <- td_get_context()$connection
    
    # Load the example data.
    loadExampleData("tdplyr_example", "titanic")
    
    # Create tbl_teradata object.
    titanic_data <- tbl(con, "titanic")
    
    # Check the list of available analytic functions.
    display_analytic_functions()
    
    # Example 1: Apply 'TOUPPER' string operator to the
    #            specified input "name" columns.
    obj <- td_str_apply_sqle(data=titanic_data,
            target.columns='name',
            string.operation='TOUPPER',
            in.place=FALSE)
    
    # Print the result.
    print(obj$result)
    
    # Example 2: Apply td_str_apply_sqle using all the arguments.
    obj <- td_str_apply_sqle(
            data=titanic_data,
            data.partition.column='age',
            data.order.column='age',
            target.columns='name',
            accumulate='passenger',
            output.columns='str_op_output',
            string.operation='TOUPPER',
            in.place=FALSE,
            persist=TRUE)
    
    # Print the result.
    print(obj$result)