Creating R Objects from Teradata Vantage Data Source | Teradata R Package - 17.00 - Creating R Objects from Teradata Vantage Data Source - Teradata R Package

Teradata® R Package User Guide

prodname
Teradata R Package
vrm_release
17.00
created_date
November 2020
category
User Guide
featnum
B700-4005-090K

Create a tibble from a table in Vantage

Use the tbl() function of the "dplyr" package to create a tdplyr tibble from an existing table in a Vantage database.

A tdplyr tibble is an R table that resembles an R tibble, that is, a form of data frame. The difference between a tdplyr tibble and an R tibble is that the output object of tbl() function shows that a tdplyr tibble is a remote source in a database in Vantage.

For example:

The following command creates a tdplyr tibble object "tddf_iris" from the existing table "iris_flowers" in Vantage.

Enter the command:

> tddf_iris <- tbl(con, "iris_flowers")

At the prompt, enter tddf_iris to receive the following output (first ten rows shown here):

# Source: table<iris_flowers> [?? x 5]
# Database: [Teradata 16.20.49.01] [Teradata Native Driver 16.20.0.34]
# [TDAPUSER@<hostname>/TDAPUSERDB]
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species  
          <dbl>       <dbl>        <dbl>       <dbl> <chr>    
 1          6.2         2.9          4.3         1.3 versicolor
 2          7.3         2.9          6.3         1.8 virginica
 3          6.3         3.3          4.7         1.6 versicolor
 4          6.3         2.5          4.9         1.5 versicolor
 5          7.1         3            5.9         2.1 virginica
 6          5.4         3.9          1.7         0.4 setosa   
 7          5.4         3.7          1.5         0.2 setosa   
 8          5.4         3.9          1.3         0.4 setosa   
 9          7.2         3.6          6.1         2.5 virginica
10          7.2         3.2          6           1.8 virginica
# ... with more rows

Create an R data frame from a tibble

Create an R data frame from a tibble by using the as.data.frame() R function on a tdplyr tibble, to transfer the data of the corresponding Vantage table into an R data frame on the client machine.

The optional n argument of the as.data.frame() function specifies the number of rows to be pulled from the Vantage table.

For Example:

The following statement transfers 20 rows from the "iris_flowers" Vantage table into the "df_iris" data frame on the client by applying the as.data.frame() function on the "tddf_iris" tibble:

> df_iris <- as.data.frame(tddf_iris, n=20)

See Teradata R Package Limitations for details on using the as.data.frame() function.