Teradata Package for R Function Reference | 17.00 - td_to_csv - 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

Product
Teradata Package for R
Release Number
17.00
Published
July 2021
Language
English (United States)
Last Update
2023-08-08
dita:id
B700-4007
NMT
no
Product Category
Teradata Vantage
Export data to CSV file.

Description

The td_to_csv function exports data from Teradata Vantage to CSV file with or without FastExport protocol.

Usage

td_to_csv(
  df,
  csv.file.name,
  use.fastexport = NA,
  num.rows = 9999,
  all.rows = FALSE,
  catch.errors.warnings = TRUE,
  ...
)

Arguments

df

Required Argument.
Specifies the tbl_teradata containing the data to be extracted.
Types: tbl_teradata

csv.file.name

Required Argument.
Specifies the name of CSV file to export the data into.
The file will get created if not present and will be overwritten if present.
Types: str

use.fastexport

Optional Argument.
Specifies whether FastExport protocol should be used or not while exporting data. When set to TRUE, data is exported using FastExport protocol. When set to NA, the approach is decided based on the number of rows to be exported.
Notes:

  1. Teradata recommends to use FastExport when number of rows in R dataframe are at least 100,000. To extract lesser rows, ignore this option and go with regular approach. FastExport opens multiple data transfer connections to the database.

  2. FastExport does not support all Teradata Database data types. For example, tables with BLOB and CLOB type columns cannot be extracted.

  3. FastExport cannot be used to extract data from a volatile or temporary table.

  4. For best efficiency, do not use groupby() and sort() with FastExport.

For additional information about fastexport protocol through teradatasql driver, please refer the FastExport section of terdatasql driver documentation.
Default Value: FALSE
Types: bool

num.rows

Optional Argument.
Specifies the number of rows to export.
Note:

  1. This argument is ignored if "all.rows" is set to TRUE.

Default Value: 99999
Types: int

all.rows

Optional Argument.
Specifies whether all rows should be exported to CSV or not.
Default Value: FALSE
Types: bool

catch.errors.warnings

Optional Argument.
Specifies whether to catch errors and warnings (if any) raised by FastExport protocol while converting tbl_teradata to R dataframe.
Default Value: TRUE
Types: logical

...

Optional Argument.
Specifies additional arguments required for future enhancements.

Value

Function returns a named list containing the following objects:

  1. errors (only if "catch.errors.warnings" is set to TRUE):

    1. If there are no errors, this contains NULL.

    2. If there are errors, this contains a R dataframe containing the errors.

  2. warnings (only if "catch.errors.warnings" is set to TRUE):

    1. If there are no warnings, this contains NULL.

    2. If there are errors, this contains a R dataframe containing the warnings.

Named list member can be referenced directly with the "$" operator.

See Also

td_fastload td_fastexport

Examples


# Note: Connection must be established before running td_to_csv().

# Load the required tables.
loadExampleData("time_series_example", "ocean_buoys_seq")

# Create object(s) of class "tbl_teradata".
df_seq <- tbl(con, "ocean_buoys_seq")

# Example 1: Export the data in a csv file along with the errors and warnings, if any,
#            while extracting the data.
val <- td_to_csv(df = df1,
                 csv.file.name = 'test.csv')

# Example 2: Export the data without errors and warnings.
val <- td_to_csv(df = df1,
                 csv.file.name = 'test.csv',
                 catch.errors.warnings = FALSE)

# Example 3: Export the data in a csv file, with all.rows set to TRUE and 
#            catch errors and warnings, if any.
val <- td_to_csv(df = df1,
                 csv.file.name = 'test.csv',
                 all.rows = TRUE,
                 catch.errors.warnings = TRUE)

# Example 4: Export the data in a csv file using the specified 
#            field.quote.char and field.separator.
td_to_csv(df = df_seq,
          csv.file.name ="test.csv",
          field.separator=";",
          field.quote.char="'",
          catch.errors.warnings = FALSE)

# Example 5: Export the data in a csv file using use.fastexport = TRUE.
td_to_csv(df = df_seq,
          csv.file.name ="test.csv",
          use.fastexport=TRUE,
          open.sessions = 4,
          catch.errors.warnings = FALSE)

# Example 6: Export the data in a csv file using num.rows = 10500.
td_to_csv(df = df_seq,
          csv.file.name ="test.csv",
          num.rows = 10500,
          catch.errors.warnings = FALSE)