How to customize prefix argument in s3sync function using R

39 views Asked by At

I want to download a set of csv files from a S3 subfolder with example path s3://folder/subfolder/date=2023-03-20. The subfolder has folders containing these csv files, which are created everyday with pattern: /date=<todays date>/. I am unable to set this pattern in the prefix argument in s3sync function. Is there a way to add this pattern?

This is my code in R:

key <- "ABCD" # access key ID
secret <- "XYZ" #secret key

Sys.setenv("AWS_ACCESS_KEY_ID" = key,
       "AWS_SECRET_ACCESS_KEY" = secret,
       "AWS_DEFAULT_REGION" ="Global")

### get todays date
today <- as.character(paste('date=',Sys.Date(),sep=""))
today

s3sync (path=".", bucket="s3://my_bucket",prefix="folder/subfolder/today ", region="Global", direction="download")
1

There are 1 answers

1
Leon Samson On

I think you are almost there. Try:

myprefix <- paste0("folder/subfolder/", today)
s3sync (path=".", bucket="s3://my_bucket",prefix=myprefix, region="Global", direction="download")