write_civis {civis}R Documentation

Upload a local data frame or csv file to the Civis Platform (Redshift)

Description

Uploads a data frame, a csv file, or file on S3 to Redshift based on the first argument.

A default database can be set using options(civis.default_db = "my_database"). If there is only one database available, this database will automatically be used as the default.

Usage

write_civis(x, ...)

## S3 method for class 'data.frame'
write_civis(
  x,
  tablename,
  database = NULL,
  if_exists = "fail",
  distkey = NULL,
  sortkey1 = NULL,
  sortkey2 = NULL,
  max_errors = NULL,
  verbose = FALSE,
  hidden = TRUE,
  diststyle = NULL,
  header = TRUE,
  credential_id = NULL,
  import_args = NULL,
  ...
)

## S3 method for class 'character'
write_civis(
  x,
  tablename,
  database = NULL,
  if_exists = "fail",
  distkey = NULL,
  sortkey1 = NULL,
  sortkey2 = NULL,
  max_errors = NULL,
  verbose = FALSE,
  hidden = TRUE,
  diststyle = NULL,
  header = TRUE,
  credential_id = NULL,
  import_args = NULL,
  ...
)

## S3 method for class 'numeric'
write_civis(
  x,
  tablename,
  database = NULL,
  if_exists = "fail",
  distkey = NULL,
  sortkey1 = NULL,
  sortkey2 = NULL,
  max_errors = NULL,
  verbose = FALSE,
  delimiter = ",",
  hidden = TRUE,
  diststyle = NULL,
  header = TRUE,
  credential_id = NULL,
  import_args = NULL,
  ...
)

Arguments

x

data frame, file path of a csv, or the id of a csv file on S3 to upload to platform.

...

arguments passed to write.csv.

tablename

string, Name of table and schema "schema.tablename".

database

string, Name of database where data frame is to be uploaded. If no database is specified, uses options(civis.default_db).

if_exists

string, optional, String indicating action to take if table already exists. Must be either "fail", "drop", "truncate" or "append". Defaults to "fail".

distkey

string, optional, Column name designating the distkey.

sortkey1

string, optional, Column name designating the first sortkey.

sortkey2

string, optional, Column name designating the second (compound) sortkey.

max_errors

int, optional, Maximum number of rows with errors to remove before failing.

verbose

bool, Set to TRUE to print intermediate progress indicators.

hidden

bool, if TRUE (default), this job will not appear in the Civis UI.

diststyle

string optional. The diststyle to use for the table. One of "even", "all", or "key".

header

bool, if TRUE (default) the first row is a header.

credential_id

integer, the id of the credential to be used when performing the database import. If NULL (default), the default credential of the current user will be used.

import_args

list of additional arguments for imports_post_files.

delimiter

string, optional. Which delimiter to use. One of ',', '\t' or '|'.

Methods (by class)

See Also

refresh_table to update table meta-data.

Other io: download_civis(), query_civis_file(), query_civis(), read_civis(), write_civis_file()

Examples

## Not run: 
df <- read.csv(local_file)

# Create new table, fail if already exists
write_civis(df, "schema.my_table", "my_database")

# Create new table, append if already exists
write_civis(df, "schema.my_table", "my_database", if_exists="append")

# Create new table with additional options
write_civis(df, "schema.my_table", "my_database",
            distkey="id",
            sortkey1="added_date",
            credential_id = 1,
            header = FALSE)

# Create new table directly from a saved csv
write_civis("my/file/path.csv", "schema.my_table", "my_database")

# Create new table from a file_id
id <- write_civis_file("my/file/path.csv", name = "path.csv")
write_civis(id, "schema.my_table", "my_database")


## End(Not run)

[Package civis version 3.1.2 Index]