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 |
tablename |
string, Name of table and schema |
database |
string, Name of database where data frame is to be uploaded. If no database is specified,
uses |
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. |
bool, if | |
diststyle |
string optional. The diststyle to use for the table. One of "even", "all", or "key". |
header |
bool, if |
credential_id |
integer, the id of the credential to be used when performing
the database import. If |
import_args |
list of additional arguments for |
delimiter |
string, optional. Which delimiter to use. One of
|
Methods (by class)
-
write_civis(data.frame)
: Upload a data frame to Civis Platform (Redshift). -
write_civis(character)
: Upload a csv to Civis Platform (Redshift). -
write_civis(numeric)
: Upload a csv file from the files endpoint to Civis Platform (Redshift)
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)