Open kadyb opened 5 months ago
Thank you for spotting this. The behavior you observed is indeed a bug in the rstac
package related to how variables are escaped in the items_filter()
function. The same bug is present in the functions assets_select()
and links()
. This has been fixed in the b-1.0.1
branch.
The fix will be included in the next release on CRAN, which should be available soon. In the meantime, you can install the development version from GitHub to use the fix right away. Here’s how you can do it using the remotes
package:
# Install the remotes package if you haven't already
install.packages("remotes")
# Install the development version of rstac from GitHub
remotes::install_github("brazil-data-cube/rstac@b-1.0.1")
Additionally, the correct way to use variables inside expressions in items_filter()
is by passing them inside double curly braces, for example {{id}}
, to ensure proper escaping. Here is your example updated with the correct syntax:
library("rstac")
stac("https://earth-search.aws.element84.com/v1") |>
stac_search(
collections = "sentinel-2-c1-l2a",
bbox = c(22, 51, 23, 52),
datetime = "2023-01-01T00:00:00Z/2023-01-02T00:00:00Z") |>
post_request() -> items
id = items$features[[1]]$properties$`s2:tile_id`
id
#> "S2A_OPER_MSI_L2A_TL_2APS_20230101T135652_A039315_T34UEB_N05.09"
# Now this works with the fix
items |>
items_filter(properties$`s2:tile_id` == {{id}})
#> - features (1 item(s) / 3 not fetched):
#> - S2A_T34UEB_20230101T093407_L2A
I appreciate your patience and contributions to rstac
package.
Best regards, Rolf
Thank you!
Additionally, the correct way to use variables inside expressions in items_filter() is by passing them inside double curly braces, for example {{id}}, to ensure proper escaping.
Maybe you can add such an example to the documentation? I wasn't aware it had to be used in this way.
I tried filtering the scene ID using the variable in
items_filter()
, but it didn't work. However, if I pass it as text, it works. Is this expected behavior?