Skip to content

Instantly share code, notes, and snippets.

@PietrH
Last active November 27, 2024 09:28
Show Gist options
  • Save PietrH/910c367d2b96fd3480635699f725f5c0 to your computer and use it in GitHub Desktop.
Save PietrH/910c367d2b96fd3480635699f725f5c0 to your computer and use it in GitHub Desktop.
Reading the OPERA radar overview json file, without jsonlite
httr2::request("https://raw.githubusercontent.com/enram/aloftdata.eu/refs/heads/main/_data/OPERA_RADARS_DB.json") |>
  httr2::req_perform() |>
  httr2::resp_body_json(check_type = FALSE) |>
  purrr::map(~dplyr::tibble(
    number = .x$number,
    country = .x$country,
    countryid = .x$countryid,
    oldcountryid = .x$oldcountryid,
    wmocode = .x$wmocode,
    odimcode = .x$odimcode,
    location = .x$location,
    status = .x$status,
    latitude = .x$latitude,
    longitude = .x$longitude,
    heightofstation = .x$heightofstation,
    band = .x$band,
    doppler = .x$doppler,
    polarization = .x$polarization,
    maxrange = .x$maxrange,
    startyear = .x$startyear,
    heightantenna = .x$heightantenna,
    diameterantenna = .x$diameterantenna,
    beam = .x$beam,
    gain = .x$gain,
    frequency = .x$frequency,
    source = .x$source
  )) |>
  purrr::list_rbind()
#> # A tibble: 281 × 22
#>    number country  countryid oldcountryid wmocode odimcode location   status
#>    <chr>  <chr>    <chr>     <chr>        <chr>   <chr>    <chr>      <chr> 
#>  1 1322   Austria  LOWM90    OSaa         11124   atval    Valluga    0     
#>  2 1128   Belgium  EBUM40    BX40         6451    bezav    Zaventem   0     
#>  3 1129   Belgium  EBUM41    BX41         6477    bewid    Wideumont  1     
#>  4 1356   Belgium  EBUM42    BX42         6410    bejab    Jabbeke    1     
#>  5 1399   Belgium  EBUM43    BX43         6475    behel    Helchteren 1     
#>  6 1342   Bulgaria BUaaX     <NA>         <NA>    <NA>     Gelemenovo 0     
#>  7 1343   Bulgaria BUaaS     <NA>         <NA>    <NA>     Gelemenovo 0     
#>  8 1218   Croatia  LDZM42    RH42         14256   hrbil    Bilogora   0     
#>  9 1218   Croatia  LDZM42    RH42         14256   hrbil    Bilogora   1     
#> 10 1219   Croatia  LDZM43    RH43         14280   hrosi    Osijek     0     
#> # ℹ 271 more rows
#> # ℹ 14 more variables: latitude <chr>, longitude <chr>, heightofstation <chr>,
#> #   band <chr>, doppler <chr>, polarization <chr>, maxrange <chr>,
#> #   startyear <chr>, heightantenna <chr>, frequency <chr>, source <chr>,
#> #   diameterantenna <chr>, beam <chr>, gain <chr>

Created on 2024-11-21 with reprex v2.1.0

httr2::request("https://raw.githubusercontent.com/enram/aloftdata.eu/refs/heads/main/_data/OPERA_RADARS_DB.json") |>
httr2::req_perform() |>
httr2::resp_body_json(check_type = FALSE) |>
purrr::map(~dplyr::tibble(
number = .x$number,
country = .x$country,
countryid = .x$countryid,
oldcountryid = .x$oldcountryid,
wmocode = .x$wmocode,
odimcode = .x$odimcode,
location = .x$location,
status = .x$status,
latitude = .x$latitude,
longitude = .x$longitude,
heightofstation = .x$heightofstation,
band = .x$band,
doppler = .x$doppler,
polarization = .x$polarization,
maxrange = .x$maxrange,
startyear = .x$startyear,
heightantenna = .x$heightantenna,
diameterantenna = .x$diameterantenna,
beam = .x$beam,
gain = .x$gain,
frequency = .x$frequency,
source = .x$source
)) |>
purrr::list_rbind()

More elegant, returns any unexpected fields as well. Still needs a dplyr::relocate() to return fields in a logical order. Maybe also add a retry and user agent in production env.

httr2::request(
  "https://raw.githubusercontent.com/enram/aloftdata.eu/refs/heads/main/_data/OPERA_RADARS_DB.json"
) |>
  httr2::req_perform() |>
  httr2::resp_body_json(check_type = FALSE) |>
  purrr::map(dplyr::as_tibble) |>
  purrr::list_rbind() |>
  dplyr::glimpse()
#> Rows: 281
#> Columns: 27
#> $ number          <chr> "1322", "1128", "1129", "1356", "1399", "1342", "1343"…
#> $ country         <chr> "Austria", "Belgium", "Belgium", "Belgium", "Belgium",…
#> $ countryid       <chr> "LOWM90", "EBUM40", "EBUM41", "EBUM42", "EBUM43", "BUa…
#> $ oldcountryid    <chr> "OSaa", "BX40", "BX41", "BX42", "BX43", NA, NA, "RH42"…
#> $ wmocode         <chr> "11124", "6451", "6477", "6410", "6475", NA, NA, "1425…
#> $ odimcode        <chr> "atval", "bezav", "bewid", "bejab", "behel", NA, NA, "…
#> $ location        <chr> "Valluga", "Zaventem", "Wideumont", "Jabbeke", "Helcht…
#> $ status          <chr> "0", "0", "1", "1", "1", "0", "0", "0", "1", "0", "0",…
#> $ latitude        <chr> "47.1575", "50.9054", "49.9135", "51.1919", "51.0702",…
#> $ longitude       <chr> "10.2131", "4.4579", "5.5044", "3.0641", "5.4054", "24…
#> $ heightofstation <chr> "2809", NA, NA, "4", NA, "250", "250", "262", "262", "…
#> $ band            <chr> "C", "C", "C", "C", "C", "X", "S", "S", "C", "S", "X",…
#> $ doppler         <chr> "Y", "Y", "Y", "Y", "N", "N", "N", "Y", "Y", "Y", "Y",…
#> $ polarization    <chr> "D", "S", "S", "D", "D", "S", "S", "S", "D", "S", "D",…
#> $ maxrange        <chr> "224", "240", "240", "240", "200", "230", "230", "240"…
#> $ startyear       <chr> "2007", "2003", "2001", "2012", "2018", "1998", "1998"…
#> $ heightantenna   <chr> "2824", "73", "585", "50", "144", "256", "256", "279",…
#> $ frequency       <chr> "5.61", "5.62", "5.64", "5.605", "5.588", "9.6", "2.9"…
#> $ finishyear      <chr> "2019", NA, NA, NA, NA, NA, NA, "2021", NA, "2022", "2…
#> $ source          <chr> "archive", "main", "main", "main", "main", "archive", …
#> $ diameterantenna <chr> NA, "4.3", "4.2", "4.2", "4.2", "4.5", "4.5", "3.7", "…
#> $ beam            <chr> NA, "0.95", "1", "1", "0.948", "0.8", "1.5", "2.1", "0…
#> $ gain            <chr> NA, "43.9", "45", "45", "43", "40", "45", "38.5", "45"…
#> $ wrwp            <chr> NA, NA, NA, NA, NA, NA, NA, "Y", NA, "Y", NA, NA, NA, …
#> $ singlerrr       <chr> NA, NA, NA, NA, NA, NA, NA, "Y", NA, NA, NA, NA, NA, N…
#> $ compositerrr    <chr> NA, NA, NA, NA, NA, NA, NA, "Y", NA, NA, NA, NA, NA, N…
#> $ wigosid         <chr> NA, NA, NA, NA, NA, NA, NA, NA, "0-21010-0-38", NA, NA…

Created on 2024-11-27 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment