Skip to content

Commit

Permalink
Push migration to httr2
Browse files Browse the repository at this point in the history
  • Loading branch information
dieghernan committed Mar 12, 2024
1 parent 5e1bf07 commit 03ef7c0
Show file tree
Hide file tree
Showing 32 changed files with 126 additions and 108 deletions.
40 changes: 21 additions & 19 deletions CITATION.cff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -----------------------------------------------------------
# CITATION file created with {cffr} R package, v0.5.0
# CITATION file created with {cffr} R package, v1.0.0
# See also: https://docs.ropensci.org/cffr/
# -----------------------------------------------------------

Expand Down Expand Up @@ -67,11 +67,10 @@ references:
url: https://www.R-project.org/
authors:
- name: R Core Team
location:
name: Vienna, Austria
year: '2024'
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
version: '>= 3.6.0'
- type: software
title: countrycode
Expand All @@ -98,17 +97,6 @@ references:
email: [email protected]
year: '2024'
version: '>= 2.0.0'
- type: software
title: httr
abstract: 'httr: Tools for Working with URLs and HTTP'
notes: Imports
url: https://httr.r-lib.org/
repository: https://CRAN.R-project.org/package=httr
authors:
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2024'
- type: software
title: rappdirs
abstract: 'rappdirs: Application Directories: Determine Where to Save Data, Caches,
Expand Down Expand Up @@ -144,11 +132,10 @@ references:
notes: Imports
authors:
- name: R Core Team
location:
name: Vienna, Austria
year: '2024'
institution:
name: R Foundation for Statistical Computing
address: Vienna, Austria
year: '2024'
- type: software
title: eurostat
abstract: 'eurostat: Tools for Eurostat Open Data'
Expand Down Expand Up @@ -201,8 +188,23 @@ references:
- family-names: Dunnington
given-names: Dewey
orcid: https://orcid.org/0000-0002-9415-4582
- family-names: Brand
given-names: Teun
name-particle: van den
orcid: https://orcid.org/0000-0002-9335-7468
year: '2024'
version: '>= 3.0.0'
- type: software
title: httr2
abstract: 'httr2: Perform HTTP Requests and Process the Responses'
notes: Suggests
url: https://httr2.r-lib.org
repository: https://CRAN.R-project.org/package=httr2
authors:
- family-names: Wickham
given-names: Hadley
email: [email protected]
year: '2024'
- type: software
title: knitr
abstract: 'knitr: A General-Purpose Package for Dynamic Report Generation in R'
Expand All @@ -219,7 +221,7 @@ references:
title: lwgeom
abstract: 'lwgeom: Bindings to Selected ''liblwgeom'' Functions for Simple Features'
notes: Suggests
url: https://github.com/r-spatial/lwgeom/
url: https://r-spatial.github.io/lwgeom/
repository: https://CRAN.R-project.org/package=lwgeom
authors:
- family-names: Pebesma
Expand Down
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ Depends:
Imports:
countrycode (>= 1.2.0),
geojsonsf (>= 2.0.0),
httr,
rappdirs (>= 0.3.0),
sf (>= 0.9.0),
utils
Suggests:
eurostat,
ggplot2 (>= 3.0.0),
httr2,
knitr,
lwgeom (>= 0.2-2),
rmarkdown,
testthat (>= 3.0.0)
VignetteBuilder:
knitr
Config/Needs/website: ropengov/rogtemplate, ragg, reactable, styler,
devtools
devtools, remotes
Config/testthat/edition: 3
Config/testthat/parallel: false
Config/testthat/parallel: true
Copyright: General Copyright © European Union, 1995 - today. See file
COPYRIGHTS for specific provisions.
Encoding: UTF-8
Expand Down
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# giscoR (development version)

- Improve documentation, stating where the parameters `country` and `region`
applies (#50, #75)
applies (#50, #75).
- Migrate to **httr2** instead of **httr**.

# giscoR 0.4.0

Expand Down
2 changes: 1 addition & 1 deletion R/gisco_get_healthcare.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Get locations of healthcare services in Europe.
#' Get locations of healthcare services in Europe
#'
#' @concept infrastructure
#' @family infrastructure
Expand Down
22 changes: 13 additions & 9 deletions R/utils_downloads.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,21 +301,21 @@ gsc_api_cache <-
))
}

# Last try with httr (#69)
# Last try with httr2 (#69)

if (inherits(err_dwnload, "try-error")) {
ops <- options()
options(timeout = 1000)
req <- try(httr::GET(url, httr::write_disk(file_local, overwrite = TRUE)),
silent = TRUE
)
options(ops)
req <- httr2::request(url)
req <- httr2::req_error(req, is_error = function(x) {
FALSE
})
req <- httr2::req_timeout(req, 100000)
resp <- httr2::req_perform(req, file_local)

# Mock err download
if (inherits(req, "try-error")) {
if (httr2::resp_is_error(resp)) {
mock_er <- "aaaa"
unlink(file_local)
} else if (httr::status_code(req) == 200) {
} else if (httr2::resp_status(resp) == 200) {
mock_er <- 200
} else {
mock_er <- "aaaa"
Expand All @@ -326,6 +326,10 @@ gsc_api_cache <-
}
# If not then stop
if (inherits(err_dwnload, "try-error")) {
gsc_message(
TRUE, "HTTP Status Code:", httr2::resp_status(resp),
"-", httr2::resp_status_desc(resp)
)
gsc_message(
TRUE,
"\nurl \n ",
Expand Down
45 changes: 23 additions & 22 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repost

<!-- badges: end -->

[giscoR](https://ropengov.github.io/giscoR//) is an API package that helps to
retrieve data from [Eurostat - GISCO (the Geographic Information System of the
COmmission)](https://ec.europa.eu/eurostat/web/gisco). It also provides some
[**giscoR**](https://ropengov.github.io/giscoR//) is an API package that helps
to retrieve data from [Eurostat - GISCO (the Geographic Information System of
the COmmission)](https://ec.europa.eu/eurostat/web/gisco). It also provides some
lightweight data sets ready to use without downloading.

[GISCO](https://ec.europa.eu/eurostat/web/gisco) is a geospatial open data
Expand All @@ -68,20 +68,20 @@ Full site with examples and vignettes on <https://ropengov.github.io/giscoR/>

## Installation

Install `giscoR` from [**CRAN**](https://CRAN.R-project.org/package=giscoR):
Install **giscoR** from [**CRAN**](https://CRAN.R-project.org/package=giscoR):

```{r, eval=FALSE}
install.packages("giscoR")
```

You can install the developing version of `giscoR` with:
You can install the developing version of **giscoR** with:

```{r, eval=FALSE}
library(remotes)
install_github("rOpenGov/giscoR")
```

Alternatively, you can install `giscoR` using the
Alternatively, you can install **giscoR** using the
[r-universe](https://ropengov.r-universe.dev/giscoR):

```{r, eval=FALSE}
Expand All @@ -105,7 +105,7 @@ if (length(l) == 4) {
}
```

This script highlights some features of `giscoR`:
This script highlights some features of **giscoR** :

```{r example}
library(giscoR)
Expand Down Expand Up @@ -165,7 +165,7 @@ ggplot(coast) +

### Labels

An example of a labeled map using `ggplot2`:
An example of a labeled map using **ggplot2**:

```{r labels, fig.height=7, fig.width=6}
ITA <- gisco_get_nuts(country = "Italy", nuts_level = 1)
Expand All @@ -178,10 +178,10 @@ ggplot(ITA) +

### Thematic maps

An example of a thematic map plotted with the `ggplot2` package. The information
is extracted via the `eurostat` package. We would follow the fantastic approach
presented by [Milos Popovic](https://milospopovic.net/) on [this
post](https://milospopovic.net/how-to-make-choropleth-map-in-r/):
An example of a thematic map plotted with the **ggplot2** package. The
information is extracted via the **eurostat** package. We would follow the
fantastic approach presented by [Milos Popovic](https://milospopovic.net/) on
[this post](https://milospopovic.net/how-to-make-choropleth-map-in-r/):

```{r eurostat_install, include = FALSE}
if (isFALSE(requireNamespace("eurostat", quietly = TRUE))) {
Expand Down Expand Up @@ -322,8 +322,8 @@ ggplot(nuts3.sf) +
## A note on caching

Some data sets (as Local Administrative Units - LAU, or high-resolution files)
may have a size larger than 50MB. You can use `giscoR` to create your own local
repository at a given local directory passing the following function:
may have a size larger than 50MB. You can use **giscoR** to create your own
local repository at a given local directory passing the following function:

```{r, eval=FALSE}
gisco_set_cache_dir("./path/to/location")
Expand All @@ -336,18 +336,19 @@ your local directory.

### API data packages

- `eurostat` package (<https://ropengov.github.io/eurostat/>). This is an API
package that provides access to open data from Eurostat.
- **eurostat** package (<https://ropengov.github.io/eurostat/>). This is an
API package that provides access to open data from Eurostat.

### Plotting `sf` objects
### Plotting **sf** objects

Some packages recommended for visualization are:

- [`tmap`](https://r-tmap.github.io/tmap/)
- [`ggplot2`](https://github.com/tidyverse/ggplot2) +
[`ggspatial`](https://github.com/paleolimbot/ggspatial)
- [`mapsf`](https://riatelab.github.io/mapsf/)
- [`leaflet`](https://rstudio.github.io/leaflet/)
- [**tmap**](https://r-tmap.github.io/tmap/)
- [**ggplot2**](https://github.com/tidyverse/ggplot2) +
[**ggspatial**](https://github.com/paleolimbot/ggspatial) +
[**tidyterra**](https://dieghernan.github.io/tidyterra/)
- [**mapsf**](https://riatelab.github.io/mapsf/)
- [**leaflet**](https://rstudio.github.io/leaflet/)

## Contribute

Expand Down
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Active](https://www.repostatus.org/badges/latest/active.svg)](https://www.repost

<!-- badges: end -->

[giscoR](https://ropengov.github.io/giscoR//) is an API package that
[**giscoR**](https://ropengov.github.io/giscoR//) is an API package that
helps to retrieve data from [Eurostat - GISCO (the Geographic
Information System of the
COmmission)](https://ec.europa.eu/eurostat/web/gisco). It also provides
Expand All @@ -44,21 +44,21 @@ Full site with examples and vignettes on

## Installation

Install `giscoR` from
Install **giscoR** from
[**CRAN**](https://CRAN.R-project.org/package=giscoR):

``` r
install.packages("giscoR")
```

You can install the developing version of `giscoR` with:
You can install the developing version of **giscoR** with:

``` r
library(remotes)
install_github("rOpenGov/giscoR")
```

Alternatively, you can install `giscoR` using the
Alternatively, you can install **giscoR** using the
[r-universe](https://ropengov.r-universe.dev/giscoR):

``` r
Expand All @@ -72,7 +72,7 @@ install.packages("giscoR",
You can have a look to the documentation of the dev version in
<https://ropengov.github.io/giscoR/dev/>

This script highlights some features of `giscoR`:
This script highlights some features of **giscoR** :

``` r
library(giscoR)
Expand Down Expand Up @@ -139,7 +139,7 @@ ggplot(coast) +

### Labels

An example of a labeled map using `ggplot2`:
An example of a labeled map using **ggplot2**:

``` r
ITA <- gisco_get_nuts(country = "Italy", nuts_level = 1)
Expand All @@ -154,9 +154,9 @@ ggplot(ITA) +

### Thematic maps

An example of a thematic map plotted with the `ggplot2` package. The
information is extracted via the `eurostat` package. We would follow the
fantastic approach presented by [Milos
An example of a thematic map plotted with the **ggplot2** package. The
information is extracted via the **eurostat** package. We would follow
the fantastic approach presented by [Milos
Popovic](https://milospopovic.net/) on [this
post](https://milospopovic.net/how-to-make-choropleth-map-in-r/):

Expand Down Expand Up @@ -281,8 +281,8 @@ ggplot(nuts3.sf) +
## A note on caching

Some data sets (as Local Administrative Units - LAU, or high-resolution
files) may have a size larger than 50MB. You can use `giscoR` to create
your own local repository at a given local directory passing the
files) may have a size larger than 50MB. You can use **giscoR** to
create your own local repository at a given local directory passing the
following function:

``` r
Expand All @@ -296,18 +296,19 @@ them on your local directory.

### API data packages

- `eurostat` package (<https://ropengov.github.io/eurostat/>). This is
- **eurostat** package (<https://ropengov.github.io/eurostat/>). This is
an API package that provides access to open data from Eurostat.

### Plotting `sf` objects
### Plotting **sf** objects

Some packages recommended for visualization are:

- [`tmap`](https://r-tmap.github.io/tmap/)
- [`ggplot2`](https://github.com/tidyverse/ggplot2) +
[`ggspatial`](https://github.com/paleolimbot/ggspatial)
- [`mapsf`](https://riatelab.github.io/mapsf/)
- [`leaflet`](https://rstudio.github.io/leaflet/)
- [**tmap**](https://r-tmap.github.io/tmap/)
- [**ggplot2**](https://github.com/tidyverse/ggplot2) +
[**ggspatial**](https://github.com/paleolimbot/ggspatial) +
[**tidyterra**](https://dieghernan.github.io/tidyterra/)
- [**mapsf**](https://riatelab.github.io/mapsf/)
- [**leaflet**](https://rstudio.github.io/leaflet/)

## Contribute

Expand Down
Loading

0 comments on commit 03ef7c0

Please sign in to comment.