4343# ' @param progress a `logical` indicating if a progress bar must be
4444# ' shown or not. Defaults to `TRUE`.
4545# '
46+ # ' @param use_gdal a `logical` indicating if the file should be downloaded
47+ # ' by GDAL instead httr package.
48+ # '
4649# ' @param download_fn a `function` to handle download of assets for
4750# ' each item to be downloaded. Using this function, you can change the
4851# ' hrefs for each asset, as well as the way download is done.
8891# ' Multiple expressions are combine with `AND` operator. Expressions can
8992# ' use `asset` helper functions (i.e. `asset_key()`, `asset_eo_bands()`,
9093# ' and `asset_raster_bands()`). Multiple expressions are combined with
91- # ' `AND` operator.
94+ # ' `AND` operator. `assets_select()` uses non-standard evaluation to evaluate
95+ # ' its expressions. That means users must escape any variable or call to
96+ # ' be able to use them in the expressions. The escape is done by using
97+ # ' `double-curly-braces`, i.e., `{{variable}}`.
9298# '
9399# ' **WARNING:** Errors in the evaluation of expressions are
94100# ' considered as `FALSE`.
117123# ' @examples
118124# ' \dontrun{
119125# ' # assets_download function
120- # ' stac("https://brazildatacube.dpi. inpe.br/stac/") %>%
121- # ' stac_search(collections = "CB4 -16D-2",
126+ # ' stac("https://data. inpe.br/bdc/ stac/v1 /") %>%
127+ # ' stac_search(collections = "CBERS4-WFI -16D-2",
122128# ' datetime = "2019-06-01/2019-08-01") %>%
123129# ' stac_search() %>%
124130# ' get_request() %>%
127133# '
128134# ' \dontrun{
129135# ' # assets_url function
130- # ' stac_item <- stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
131- # ' stac_search(collections = "CB4-16D-2", limit = 100,
132- # ' datetime = "2017-08-01/2018-03-01",
133- # ' bbox = c(-48.206,-14.195,-45.067,-12.272)) %>%
134- # ' get_request() %>% items_fetch(progress = FALSE)
136+ # ' stac_item <- stac("https://data.inpe.br/bdc/stac/v1/") %>%
137+ # ' stac_search(
138+ # ' collections = "CBERS4-WFI-16D-2",
139+ # ' limit = 100,
140+ # ' datetime = "2017-08-01/2018-03-01",
141+ # ' bbox = c(-48.206,-14.195,-45.067,-12.272)) %>%
142+ # ' get_request() %>% items_fetch(progress = FALSE)
135143# '
136144# ' stac_item %>% assets_url()
137145# ' }
138146# '
139147# ' \dontrun{
140148# ' # assets_select function
141- # ' stac_item <- stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
142- # ' stac_search(collections = "CB4-16D-2", limit = 100,
143- # ' datetime = "2017-08-01/2018-03-01",
144- # ' bbox = c(-48.206,-14.195,-45.067,-12.272)) %>%
145- # ' get_request() %>% items_fetch(progress = FALSE)
149+ # ' stac_item <- stac("https://data.inpe.br/bdc/stac/v1/") %>%
150+ # ' stac_search(
151+ # ' collections = "CBERS4-WFI-16D-2",
152+ # ' limit = 100,
153+ # ' datetime = "2017-08-01/2018-03-01",
154+ # ' bbox = c(-48.206,-14.195,-45.067,-12.272)) %>%
155+ # ' get_request() %>% items_fetch(progress = FALSE)
146156# '
147157# ' stac_item %>% assets_select(asset_names = "NDVI")
148158# ' }
@@ -182,6 +192,7 @@ assets_download <- function(items,
182192 asset_names = NULL ,
183193 output_dir = getwd(),
184194 overwrite = FALSE , ... ,
195+ use_gdal = FALSE ,
185196 download_fn = NULL ) {
186197 # check output dir
187198 if (! dir.exists(output_dir ))
@@ -197,6 +208,7 @@ assets_download.doc_item <- function(items,
197208 asset_names = NULL ,
198209 output_dir = getwd(),
199210 overwrite = FALSE , ... ,
211+ use_gdal = FALSE ,
200212 create_json = FALSE ,
201213 download_fn = NULL ) {
202214 if (! is.null(asset_names )) {
@@ -209,7 +221,7 @@ assets_download.doc_item <- function(items,
209221 }
210222 items $ assets <- lapply(
211223 items $ assets , asset_download , output_dir = output_dir ,
212- overwrite = overwrite , ... , download_fn = download_fn
224+ overwrite = overwrite , use_gdal = use_gdal , download_fn = download_fn , ...
213225 )
214226 if (create_json ) {
215227 file <- " item.json"
@@ -228,6 +240,7 @@ assets_download.doc_items <- function(items,
228240 asset_names = NULL ,
229241 output_dir = getwd(),
230242 overwrite = FALSE , ... ,
243+ use_gdal = FALSE ,
231244 download_fn = NULL ,
232245 create_json = TRUE ,
233246 items_max = Inf ,
@@ -249,7 +262,7 @@ assets_download.doc_items <- function(items,
249262 items $ features [[i ]] <- assets_download(
250263 items = items $ features [[i ]], asset_names = asset_names ,
251264 output_dir = output_dir , overwrite = overwrite ,
252- create_json = FALSE , download_fn = download_fn , ...
265+ use_gdal = use_gdal , create_json = FALSE , download_fn = download_fn , ...
253266 )
254267 }
255268 if (create_json )
@@ -336,10 +349,7 @@ assets_select <- function(items, ..., asset_names = NULL, select_fn = NULL) {
336349assets_select.doc_item <- function (items , ... ,
337350 asset_names = NULL ,
338351 select_fn = NULL ) {
339- exprs <- unquote(
340- expr = as.list(substitute(list (... ), env = environment())[- 1 ]),
341- env = parent.frame()
342- )
352+ exprs <- as.list(substitute(list (... ), env = environment()))[- 1 ]
343353 init_length <- length(items $ assets )
344354 if (! is.null(asset_names )) {
345355 asset_names <- intersect(names(items $ assets ), asset_names )
@@ -348,9 +358,10 @@ assets_select.doc_item <- function(items, ...,
348358 if (length(exprs ) > 0 ) {
349359 if (! is.null(names(exprs )))
350360 .error(" Select expressions cannot be named." )
351- for (i in seq_along(exprs )) {
361+ for (expr in exprs ) {
362+ expr <- unquote(expr = expr , env = parent.frame())
352363 sel <- map_lgl(names(items $ assets ), function (key ) {
353- select_eval(key = key , asset = items $ assets [[key ]], expr = exprs [[ i ]] )
364+ select_eval(key = key , asset = items $ assets [[key ]], expr = expr )
354365 })
355366 items $ assets <- items $ assets [sel ]
356367 }
0 commit comments