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

Teradata R Package
November 2020
User Guide

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] [Teradata Native Driver]
   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 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 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 function on the "tddf_iris" tibble:

> df_iris <-, n=20)

See Teradata R Package Limitations for details on using the function.