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

Teradata® R Package User Guide

Product
Teradata R Package
Release Number
16.20
Published
February 2020
Language
English (United States)
Last Update
2022-05-02
dita:mapPath
qbt1519078127352.ditamap
dita:ditavalPath
Generic_no_ie_no_tempfilter.ditaval

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.50.0004
#   16.50G.00.04[TDAPUSER@server.labs.teradata.com/TDAPUSERDB]
   Sepal.Length Sepal.Width Petal.Length Petal.Width Species   
          <dbl>       <dbl>        <dbl>       <dbl> <chr>     
 1          7.2         3            5.8         1.6 virginica 
 2          6.4         2.9          4.3         1.3 versicolor
 3          6.4         2.7          5.3         1.9 virginica 
 4          6.4         3.2          5.3         2.3 virginica 
 5          6.4         2.8          5.6         2.2 virginica 
 6          6.4         3.1          5.5         1.8 virginica 
 7          6.4         2.8          5.6         2.1 virginica 
 8          6.4         3.2          4.5         1.5 versicolor
 9          7.2         3.2          6           1.8 virginica 
10          7.2         3.6          6.1         2.5 virginica 
 ... 

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.