Giter Site home page Giter Site logo

dirkschumacher / rhxl Goto Github PK

View Code? Open in Web Editor NEW
11.0 4.0 1.0 80 KB

Humanitarian Exchange Language (HXL standard) in R

Home Page: https://dirkschumacher.github.io/rhxl/

License: GNU General Public License v3.0

R 100.00%
hxl humanitarian-exchange-language schema dataset r

rhxl's Introduction

Humanitarian Exchange Language in R

AppVeyor Build Status Travis-CI Build Status codecov

The goal of this package is to provide functions to handle datasets with HXL tags. It is currently work in progress. If you have any ideas on how to further develop the package, please feel free to open an issue or a pull request.

HXL is a different kind of data standard, designed to improve information sharing during a humanitarian crisis without adding extra reporting burdens. hxlstandard.org

Install

To install the current development version use devtools:

devtools::install_github("dirkschumacher/rhxl")

API by Example

Read in the aiports of Viet Nam.

data_url <- "http://ourairports.com/countries/VN/airports.hxl"
hxl_data <- as_hxl(read.csv(data_url))
head(hxl_data)
#> # A tibble: 6 x 20
#>      id ident type     name        latitude_deg longitude_deg elevation_ft
#>   <int> <chr> <chr>    <chr>              <dbl>         <dbl>        <int>
#> 1 26708 VVTS  large_a… Tan Son Nh…         10.8           107           33
#> 2 26700 VVNB  large_a… Noi Bai In…         21.2           106           39
#> 3 26697 VVDN  large_a… Da Nang In…         16.0           108           33
#> 4 26705 VVPQ  medium_… Phu Quoc I…         10.2           104           37
#> 5 26693 VVCR  medium_… Cam Ranh A…         12.0           109           40
#> 6 26702 VVPB  medium_… Phu Bai Ai…         16.4           108           48
#> # ... with 13 more variables: continent <chr>, iso_country <chr>,
#> #   iso_region <chr>, municipality <chr>, scheduled_service <int>,
#> #   gps_code <chr>, iata_code <chr>, local_code <chr>, home_link <chr>,
#> #   wikipedia_link <chr>, keywords <chr>, score <int>, last_updated <dttm>

You can get the schema as a tidy long table:

hxl_schema(hxl_data)
#> # A tibble: 35 x 3
#>    tag   attribute column_idx
#>    <chr> <chr>          <int>
#>  1 meta  id                 1
#>  2 meta  code               2
#>  3 loc   airport            3
#>  4 loc   type               3
#>  5 loc   airport            4
#>  6 loc   name               4
#>  7 geo   lat                5
#>  8 geo   lon                6
#>  9 geo   elevation          7
#> 10 geo   ft                 7
#> # ... with 25 more rows

Or as a character vector in the order of the columns:

hxl_schema_chr(hxl_data)
#>  [1] "#meta +id"                  "#meta +code"               
#>  [3] "#loc +airport +type"        "#loc +airport +name"       
#>  [5] "#geo +lat"                  "#geo +lon"                 
#>  [7] "#geo +elevation +ft"        "#region +continent +code"  
#>  [9] "#country +code +iso2"       "#adm1 +code +iso"          
#> [11] "#loc +municipality +name"   "#status +scheduled"        
#> [13] "#loc +airport +code +gps"   "#loc +airport +code +iata" 
#> [15] "#loc +airport +code +local" "#meta +url +airport"       
#> [17] "#meta +url +wikipedia"      "#meta +keywords"           
#> [19] "#meta +score"               "#date +updated"

We can also test, if a dataset supports a schema. For example, we could test if the dataset has lat/lng coordinates.

hxl_validate(hxl_data, c("#geo +lat", "#geo +lon"))
#> [1] TRUE

With this information you could for example write a function that can automatically display a dataset on a map - without much configuration by the user. It also makes sharing of information easier.

In addition you can select certain columns based on tags:

hxl_select(hxl_data, c("#geo +lat", "#geo +lon"))
#> # A tibble: 47 x 2
#>    latitude_deg longitude_deg
#>  *        <dbl>         <dbl>
#>  1        10.8            107
#>  2        21.2            106
#>  3        16.0            108
#>  4        10.2            104
#>  5        12.0            109
#>  6        16.4            108
#>  7        12.2            109
#>  8         8.73           107
#>  9        10.1            106
#> 10        20.8            107
#> # ... with 37 more rows

rhxl's People

Contributors

dirkschumacher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

dickoa

rhxl's Issues

Better print output

It would be great to replace the standard tibble output with a more informative hxl output.
A bit like below:

# A HXL tibble: 4 × 20
     id ident           type                          name latitude_deg longitude_deg elevation_ft
* <#meta +id>  <#meta +code>         <#loc +airport +type>       <#loc +airport +name>        <#geo +lat>         <#geo +lon>        <#geo +elevation +ft>
* <int> <chr>          <chr>                         <chr>        <dbl>         <dbl>        <int>
1  4976  NSFA medium_airport Faleolo International Airport    -13.83000     -172.0080           58
2 35173  NSMA  small_airport                 Maota Airport    -13.74230     -172.2580           NA
3 31127  NSFI  small_airport              Fagali'i Airport    -13.84870     -171.7400          131
4 30608  NSAU  small_airport                  Asau Airport    -13.50513     -172.6279           NA
# ... with 13 more variables: continent <chr>, iso_country <chr>, iso_region <chr>,
#   municipality <chr>, scheduled_service <int>, gps_code <chr>, iata_code <chr>, local_code <chr>,
#   home_link <chr>, wikipedia_link <chr>, keywords <chr>, score <int>, last_updated <dttm>

# Schema: #meta +id, #meta +code, #loc +airport +type, #loc +airport +name, #geo +lat, #geo +lon, #geo +elevation +ft, 
# ... with 13 more tags: #region +continent +code, #country +code +iso2, #adm1 +code +iso, #loc +municipality +name, #status +scheduled, 
# #loc +airport +code +gps, #loc +airport +code +iata, #loc +airport +code +local, #meta +url +airport, #meta +url +wikipedia, #meta +keywords, #meta +score, #date +updated

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.