7.00.02.01 - Example of Running an R Script using Aster Stream - Aster R

Teradata Aster® R User GuideUpdate 3

prodname
Aster R
vrm_release
7.00.02.01
created_date
December 2017
category
Programming Reference
User Guide
featnum
B700-1033-700K
This example uses the same input as in Example 3: Custom R Function. Users must make sure that the Input table is in the Aster Database and is named "fruit".

This example uses the same R script as in Example 1: Simple Calculation.

  1. Retrieve content from the input table "fruit".
    select * from fruit;
  2. Install the R script on the cluster.
    \install fruit_1104b.R
  3. Run the Stream function call.
    • Users can run the Stream function call directly, and the output is shown on the screen.
      select * from stream (on fruit 
      script('Rexec --vanilla fruit_1104b.R') 
      outputs('SaleDate varchar', 'DailySales numeric','DailyProfit numeric') 
      delimiter('\t') 
      );
      
       SaleDate | DailySales | DailyProfit 
      ----------+------------+-------------    
       5/1/2010 |       29.8 |        5.65
       5/2/2010 |      31.78 |         6.8
       5/3/2010 |      19.25 |        4.72
       5/4/2010 |      20.57 |        5.72
      (4 rows)
    • Alternatively, users can create a table to save the output in the database, by wrapping the Stream function call in a CREATE TABLE call.
      create dimension table WeeklyTable as
      (select * from stream (on fruit 
      script('Rexec --vanilla fruit_1104b.R') 
      outputs('SaleDate varchar', 'DailySales numeric','DailyProfit numeric') 
      delimiter('\t') 
      ));

      Users can then run the select command to display the result table. The output is the same as the output of running the Stream function call directly.

      select * from WeeklyTable;