write_civis_file {civis}R Documentation

Upload a R object or file to Civis Platform (Files endpoint)

Description

Uploads a data frame, R object or file to the files endpoint on Civis Platform (Amazon S3). It returns the id of the file for use with read_civis or download_civis.

Data frames are uploaded as CSVs with write.csv. R objects are serialized with saveRDS. Files are uploaded as-is. Objects or files larger than 50mb are chunked and can be uploaded in parallel if a plan has been set. Files larger than 5TB cannot be uploaded.

Usage

write_civis_file(x, ...)

## Default S3 method:
write_civis_file(x, name = "r-object.rds", expires_at = NULL, ...)

## S3 method for class 'data.frame'
write_civis_file(
  x,
  name = "data.csv",
  expires_at = NULL,
  row.names = FALSE,
  ...
)

## S3 method for class 'character'
write_civis_file(x, name = x, expires_at = NULL, ...)

Arguments

x

R object or path of file to upload.

...

arguments passed to saveRDS or write.csv for data frames.

name

string, Name of the file or object.

expires_at

string, The date and time the object will expire on in the format "YYYY-MM-DD HH:MM:SS". expires_at = NULL allows files to be kept indefinitely.

row.names

default FALSE. Either a logical value indicating whether the row names of x are to be written along with x, or a character vector of row names to be written.

Details

Data frames are uploaded as CSVs using write.csv, with row.names = FALSE by default. Additional arguments to write.csv can be passed through ....

By default, R objects are serialized using saveRDS before uploading the object to the files endpoint. If given a filepath, the file is uploaded as-is.

Value

The file id which can be used to later retrieve the file using read_civis.

Methods (by class)

See Also

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

Examples

## Not run: 
data(iris)
file_id <- write_civis_file(iris)
read_civis(file_id)

file_id <- write_civis_file("path/to/my.csv")
read_civis(file_id)
read_civis(file_id, using = readr::read_csv)

file_id <- write_civis_file(list(a = 1))
read_civis(file_id, using = readRDS)

# Does not expire
file_id <- write_civis_file(iris, expires_at = NULL)

# Expires on a given date and time
file_id <- write_civis_file(iris, expires_at = "2030-01-01")
file_id <- write_civis_file(iris, expires_at = "12:00:00")
file_id <- write_civis_file(iris, expires_at = "2030-01-01 12:00:00")

# Upload a large file in parallel.
library(future)
plan(multisession)
file_id <- write_civis_file("my_large_file")

## End(Not run)

[Package civis version 3.0.0 Index]