Write a CSV file to Google Cloud Storage
gcs_write_csv.RdWrites a data frame to a CSV file in Google Cloud Storage using the arrow package. Optionally returns metadata about the uploaded object.
Arguments
- data
A data frame to write to GCS.
- bucket
Character string. The name of the GCS bucket to write to.
- object
Character string. The destination path for the CSV file within the bucket (e.g., "folder/subfolder/filename.csv").
- meta
Logical. If
TRUE, returns a list with object metadata. IfFALSE(default), returns the GCS path invisibly.
Value
If meta = TRUE, a list containing:
path: The full GCS path to the objectmd5_hash: The MD5 hash of the uploaded objectgeneration: The object's generation numbersize: The object size in bytesupdated: The last update timestamp
If meta = FALSE, the GCS path (invisibly).
Details
This function uses arrow's CSV writer for efficient writing of data frames to GCS. The file is written directly to the specified GCS path without requiring temporary local storage.
When meta = TRUE, the function retrieves and returns metadata about the
uploaded object including:
The GCS path
MD5 hash for integrity verification
Generation number for versioning
File size
Last updated timestamp
See also
arrow::write_csv_arrow() for write options,
googleCloudStorageR::gcs_get_object() for metadata retrieval
Examples
if (FALSE) { # \dontrun{
# Write a data frame to GCS
gcs_write_csv(mtcars, "my-project-data", "output/mtcars.csv")
# Write and get metadata back
meta <- gcs_write_csv(mtcars, "my-project-data", "output/mtcars.csv", meta = TRUE)
print(meta$md5_hash)
# Use with authentication
gcs_auth_bucket("my-project-data")
gcs_write_csv(my_data, "my-project-data", "processed/results.csv")
} # }