|
24 | 24 | #' @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. |
25 | 25 | #' @param Cores Numeric. How many cores to use when carrying out temporal aggregation. Default is 1. |
26 | 26 | #' @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. |
28 | 29 | #' |
29 | 30 | #' @importFrom tools file_path_sans_ext |
30 | 31 | #' @importFrom terra rast |
@@ -155,7 +156,8 @@ CDownloadS <- function(Variable = NULL, # which variable |
155 | 156 | TChunkSize = 6000, |
156 | 157 | Cores = 1, # parallelisation |
157 | 158 | verbose = TRUE, # verbosity |
158 | | - Keep_Raw = FALSE |
| 159 | + Keep_Raw = FALSE, |
| 160 | + Save_Final = TRUE |
159 | 161 | ){ |
160 | 162 | ## Catching Most Frequent Issues =============== |
161 | 163 | #--- API Credentials |
@@ -325,12 +327,14 @@ CDownloadS <- function(Variable = NULL, # which variable |
325 | 327 | terra::metags(CDS_rast) <- Meta_vec |
326 | 328 |
|
327 | 329 | ### 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 | + } |
334 | 338 | } |
335 | 339 |
|
336 | 340 | ### unlink temporary files |
|
0 commit comments