Skip to content

Instantly share code, notes, and snippets.

@davidtedfordholt
Last active May 19, 2020 20:37
Show Gist options
  • Save davidtedfordholt/0e6650e1da20ad064bbcbd6d5e8d23ba to your computer and use it in GitHub Desktop.
Save davidtedfordholt/0e6650e1da20ad064bbcbd6d5e8d23ba to your computer and use it in GitHub Desktop.
copy dataset to CSV in google storage using cloudml
copy_to_gcp <- function(.data, filename_prefix, gcp_folder = NULL, gcp_bucket) {
if (!startsWith(gcp_bucket, "gs://")) {
gcp_bucket <- paste0("gs://", gcp_bucket)
}
source <- paste0(filename_prefix, "_", format(Sys.Date(), "%Y%m%d"), ".csv")
destination <- ifelse(is.null(gcp_folder), gcp_bucket, paste0(gcp_bucket, "/", gcp_folder))
packageStartupMessage("Writing file")
write.csv(.data, source)
packageStartupMessage("Copying file")
cloudml::gs_copy(source, destination)
packageStartupMessage("Removing file")
file.remove(source)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment