This retrieves an object directly.
gcs_get_object( object_name, bucket = gcs_get_global_bucket(), meta = FALSE, saveToDisk = NULL, overwrite = FALSE, parseObject = TRUE, parseFunction = gcs_parse_download )
object_name | name of object in the bucket that will be URL encoded, or a |
---|---|
bucket | bucket containing the objects. Not needed if using a |
meta | If TRUE then get info about the object, not the object itself |
saveToDisk | Specify a filename to save directly to disk |
overwrite | If saving to a file, whether to overwrite it |
parseObject | If saveToDisk is NULL, whether to parse with |
parseFunction | If saveToDisk is NULL, the function that will parse the download. Defaults to gcs_parse_download |
The object, or TRUE if successfully saved to disk.
This differs from providing downloads via a download link as you can do via gcs_download_url
object_name
can use a gs://
URI instead,
in which case it will take the bucket name from that URI and bucket
argument
will be overridden. The URLs should be in the form gs://bucket/object/name
By default if you want to get the object straight into an R session the parseFunction is gcs_parse_download which wraps httr
's content.
If you want to use your own function (say to unzip the object) then supply it here. The first argument should take the downloaded object.
Other object functions:
gcs_compose_objects()
,
gcs_copy_object()
,
gcs_delete_object()
,
gcs_list_objects()
,
gcs_metadata_object()
if (FALSE) { ## something to download ## data.frame that defaults to be called "mtcars.csv" gcs_upload(mtcars) ## get the mtcars csv from GCS, convert it to an R obj gcs_get_object("mtcars.csv") ## get the mtcars csv from GCS, save it to disk gcs_get_object("mtcars.csv", saveToDisk = "mtcars.csv") ## default gives a warning about missing column name. ## custom parse function to suppress warning f <- function(object){ suppressWarnings(httr::content(object, encoding = "UTF-8")) } ## get mtcars csv with custom parse function. gcs_get_object("mtcars.csv", parseFunction = f) ## download an RDS file using helper gcs_parse_rds() gcs_get_object("obj.rds", parseFunction = gcs_parse_rds) ## to download from a folder in your bucket my_folder <- "your_folder/" objs <- gcs_list_objects(prefix = my_folder) dir.create(my_folder) # download all the objects to that folder dls <- lapply(objs$name, function(x) gcs_get_object(x, saveToDisk = x)) }