download_civis {civis}R Documentation

Download a table or a file from the Civis Platform to local disk

Description

download_civis downloads a file based on the type of its first argument, which can be a string "schema.table", a SQL query sql(...), or a numeric file ID.

A table or a query from Redshift will be downloaded onto disk as a CSV. A file from Platform files endpoint will be downloaded as is.

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

download_civis(x, ...)

## S3 method for class 'character'
download_civis(
  x,
  database = NULL,
  file,
  overwrite = FALSE,
  progress = FALSE,
  split = FALSE,
  job_name = NULL,
  hidden = TRUE,
  verbose = FALSE,
  ...
)

## S3 method for class 'sql'
download_civis(
  x,
  database = NULL,
  file,
  overwrite = FALSE,
  progress = FALSE,
  split = FALSE,
  job_name = NULL,
  hidden = TRUE,
  verbose = FALSE,
  ...
)

## S3 method for class 'numeric'
download_civis(x, file, overwrite = FALSE, progress = FALSE, ...)

Arguments

x

"schema.table", sql("query"), or a file id.

...

Currently ignored.

database

string, The database. If NULL, tries to use the default database.

file

string, The file to write to.

overwrite

logical, Whether to overwrite the existing file.

progress

logical, Whether to display a progress bar.

split

logical, Whether to download a big table by splitting it into multiple CSV parts first. See civis_to_multifile_csv for details.

job_name

string, Name of the job (default: "Civis Download Via R Client").

hidden

logical, Whether the job is hidden on Platform.

verbose

logical, Whether to print detailed updates of job status.

Value

The file where the downloaded files or tables are written to. It is returned invisibly.

Methods (by class)

See Also

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

Examples

## Not run: 
# Download all columns in a single table into a CSV
download_civis("schema.table", database = "my_database",
               file = "~/Downloads/my_table.csv")

# Download data from a SQL select statement into a CSV
query <- sql("SELECT * FROM table JOIN other_table USING id WHERE var1 < 23")
download_civis(query, database = "my_database",
               file = "~/Downloads/my_table.csv")

# Set a default database
options(civis.default_db = "my_database")

# Download any file from the files endpoint.
file_id <- write_civis_file(df)
download_civis(file_id, file = "df.rds", progress = TRUE)
df2 <- readRDS("df.rds")
identical(df, df2)

## End(Not run)

[Package civis version 3.1.2 Index]