Skip to content

Commit 31ae996

Browse files
committed
Resolving #20
1 parent f2d8603 commit 31ae996

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

R/CDownloadS.R

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
#' @param TChunkSize Numeric. Number of layers to bundle in each individual download. Default is 6000 to adhere to most restrictive CDS limits: https://cds.climate.copernicus.eu/live/limits.
2525
#' @param Cores Numeric. How many cores to use when carrying out temporal aggregation. Default is 1.
2626
#' @param verbose Logical. Whether to print/message function progress in console or not.
27-
#' @param Keep_Raw Logical. Whether to retain raw downloaded data or not.
27+
#' @param Keep_Raw Logical. Whether to retain raw downloaded data or not. Default is FALSE.
28+
#' @param Save_Final Logical. Whether to write the final SpatRaster to the hard drive. Default is TRUE.
2829
#'
2930
#' @importFrom tools file_path_sans_ext
3031
#' @importFrom terra rast
@@ -155,7 +156,8 @@ CDownloadS <- function(Variable = NULL, # which variable
155156
TChunkSize = 6000,
156157
Cores = 1, # parallelisation
157158
verbose = TRUE, # verbosity
158-
Keep_Raw = FALSE
159+
Keep_Raw = FALSE,
160+
Save_Final = TRUE
159161
){
160162
## Catching Most Frequent Issues ===============
161163
#--- API Credentials
@@ -325,12 +327,14 @@ CDownloadS <- function(Variable = NULL, # which variable
325327
terra::metags(CDS_rast) <- Meta_vec
326328

327329
### write file
328-
if(FileExtension == ".tif"){
329-
terra::writeRaster(CDS_rast, filename = file.path(Dir, FileName))
330-
}
331-
if(FileExtension == ".nc"){
332-
CDS_rast <- Meta.NC(NC = CDS_rast, FName = file.path(Dir, FileName),
333-
Attrs = terra::metags(CDS_rast), Write = TRUE)
330+
if(Save_Final){
331+
if(FileExtension == ".tif"){
332+
terra::writeRaster(CDS_rast, filename = file.path(Dir, FileName))
333+
}
334+
if(FileExtension == ".nc"){
335+
CDS_rast <- Meta.NC(NC = CDS_rast, FName = file.path(Dir, FileName),
336+
Attrs = terra::metags(CDS_rast), Write = TRUE)
337+
}
334338
}
335339

336340
### unlink temporary files

man/CDownloadS.Rd

Lines changed: 5 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)