Skip to content

Commit

Permalink
Merge pull request #128 from OldLipe/b-0.9.2-1
Browse files Browse the repository at this point in the history
Hotfix - Change vignettes names
  • Loading branch information
OldLipe authored Jan 21, 2023
2 parents 4a3efa9 + 2431e80 commit 821d2b4
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 66 deletions.
6 changes: 3 additions & 3 deletions R/deprec-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ assets_filter <- function(items, ..., filter_fn = NULL) {
assets_filter.STACItemCollection <- function(items, ..., filter_fn = NULL) {
# signal the deprecation to the user
lifecycle::deprecate_soft(
when = "0.9.2",
when = "0.9.2-1",
what = "rstac::assets_filter()",
with = "rstac::assets_select()"
)
Expand Down Expand Up @@ -76,7 +76,7 @@ assets_filter.STACItemCollection <- function(items, ..., filter_fn = NULL) {
assets_filter.STACItem <- function(items, ..., filter_fn = NULL) {
# signal the deprecation to the user
lifecycle::deprecate_soft(
when = "0.9.2",
when = "0.9.2-1",
what = "rstac::assets_filter()",
with = "rstac::assets_select()"
)
Expand Down Expand Up @@ -113,7 +113,7 @@ assets_filter.STACItem <- function(items, ..., filter_fn = NULL) {
items_group <- function(items, ..., field = NULL, index = NULL) {
# signal the deprecation to the user
lifecycle::deprecate_soft(
when = "0.9.2",
when = "0.9.2-1",
what = "rstac::items_group()"
)

Expand Down
43 changes: 26 additions & 17 deletions R/preview-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#'
#' @export
preview_plot <- function(url) {
preview_check(url)
img <- preview_read_file(url)
plot(1:10, ty = "n", axes = F, xlab = "", ylab = "")
grid::grid.raster(img)
Expand All @@ -24,30 +25,38 @@ preview_switch <- function(url, ...) {
switch(type, ..., .error("File type '%s' not supported", type))
}

preview_check <- function(url) {
preview_switch(
url,
png = if (!requireNamespace("png", quietly = TRUE))
.error(paste(
"This function requires `png` package. Please, use",
"install.packages('png')."
))
,
jpeg = if (!requireNamespace("jpeg", quietly = TRUE))
.error(paste(
"This function requires `jpeg` package. Please, use",
"install.packages('jpeg')."
))
)
}

# nocov start

preview_read_file <- function(url) {
temp_file <- tempfile(fileext = paste0(".", preview_file_type(url)))
on.exit(unlink(temp_file))
utils::download.file(url, destfile = temp_file, quiet = TRUE, mode = "wb")
make_get_request(
url = url,
httr::write_disk(path = temp_file, overwrite = TRUE),
error_msg = "Error in downloading"
)
preview_switch(
url,
png = {
if (!requireNamespace("png", quietly = TRUE))
.error(paste(
"This function requires `png` package. Please, use",
"install.packages('png')."
))
png::readPNG(temp_file)
},
jpeg = {
if (!requireNamespace("jpeg", quietly = TRUE))
.error(paste(
"This function requires `jpeg` package. Please, use",
"install.packages('jpeg')."
))
jpeg::readJPEG(temp_file)
})
png = png::readPNG(temp_file),
jpeg = jpeg::readJPEG(temp_file)
)
}

# nocov end
64 changes: 36 additions & 28 deletions tests/testthat/test-examples.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,49 +98,57 @@ testthat::test_that("examples rstac", {
# test items_group
testthat::expect_error(
object =
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group()
suppressWarnings(
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group()
)
)

# test items_group
testthat::expect_error(
object =
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group()
suppressWarnings(
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group()
)
)

# test items_group
testthat::expect_error(
object =
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group(field = "test", index = "test")
suppressWarnings(
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group(field = "test", index = "test")
)
)

# test items_group
testthat::expect_error(
object =
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group(index = list(1, 2, 3))
suppressWarnings(
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "LCC_C4_64_1M_STK_GO_PA-SPC-AC-NA-1",
limit = 500,
datetime = "2018-09-01/2019-08-31") %>%
get_request() %>%
items_fetch() %>%
items_group(index = list(1, 2, 3))
)
)

# test items_reap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ date: "2023-01-09"
output:
html_document:
df_print: tibble
theme:
base_font:
google: IBM Plex Serif
code_font:
google: IBM Plex Mono
classoption: x11names
fontsize: 10,5pt
indent: yes
Expand Down Expand Up @@ -359,7 +354,7 @@ is_accessible <- is_online && tryCatch({
})
```

```{r plot-preview, eval=is_accessible}
```{r plot-preview, eval=is_accessible, fig.height=3, fig.width=5}
second_item <- items_fetched$features[[2]]
second_item |>
assets_url(asset_names = "thumbnail") |>
Expand Down
5 changes: 0 additions & 5 deletions vignettes/02-cql2-example.Rmd → vignettes/rstac-02-cql2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ date: "2022-12-16"
output:
html_document:
df_print: tibble
theme:
base_font:
google: IBM Plex Serif
code_font:
google: IBM Plex Mono
classoption: x11names
fontsize: 10,5pt
indent: yes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ date: "2022-12-21"
output:
html_document:
df_print: tibble
theme:
base_font:
google: IBM Plex Serif
code_font:
google: IBM Plex Mono
classoption: x11names
fontsize: 10,5pt
indent: yes
Expand Down Expand Up @@ -146,7 +141,7 @@ is_accessible <- is_online && tryCatch({
})
```

```{r asset-preview, eval=is_accessible}
```{r asset-preview, eval=is_accessible, fig.height=3, fig.width=5}
selected_item$assets[["rendered_preview"]]$href
selected_item |>
Expand Down Expand Up @@ -189,7 +184,7 @@ We can load up that single COG file using packages like [stars](https://github.c
library(stars)
selected_item |>
assets_url(asset_names = "blue", append_gdalvsi = TRUE) |>
stars::read_stars(RasterIO = list(nBufXSize = 1024, nBufYSize = 1024)) |>
stars::read_stars(RasterIO = list(nBufXSize = 512, nBufYSize = 512)) |>
plot(main = "blue")
```

Expand Down

0 comments on commit 821d2b4

Please sign in to comment.