Usage

library(idmc)

The simple use for the idmc package is to retrieve the data from the API directly into R.

df <- idmc_get_data()
df
#> # A tibble: 51,408 × 37
#>        id country     iso3  latitude longitude centroid  role  displacement_type
#>     <int> <chr>       <chr>    <dbl>     <dbl> <chr>     <chr> <chr>            
#>  1 224900 Portugal    PRT       39.9     -8.65 [39.9112… Reco… Disaster         
#>  2 224767 India       IND       20.4     82.2  [20.4311… Reco… Conflict         
#>  3 224915 Spain       ESP       36.7     -6.08 [36.6898… Reco… Disaster         
#>  4 224622 Mexico      MEX       17.4    -92.5  [17.3704… Reco… Conflict         
#>  5 224624 Mexico      MEX       16.8    -92.5  [16.8476… Reco… Conflict         
#>  6 224623 Mexico      MEX       16.7    -91.9  [16.6675… Reco… Conflict         
#>  7 225567 Cameroon    CMR       10.7     13.8  [10.6662… Reco… Conflict         
#>  8 224647 New Zealand NZL      -37.7    176.   [-37.700… Reco… Disaster         
#>  9 225566 Cameroon    CMR       12.7     14.4  [12.7429… Reco… Conflict         
#> 10 224437 Mexico      MEX       17.6    -93.0  [17.6197… Reco… Disaster         
#> # ℹ 51,398 more rows
#> # ℹ 29 more variables: qualifier <chr>, figure <int>, displacement_date <date>,
#> #   displacement_start_date <date>, displacement_end_date <date>, year <int>,
#> #   event_id <int>, event_name <chr>, event_codes <chr>,
#> #   event_code_types <chr>, event_start_date <date>, event_end_date <date>,
#> #   category <chr>, subcategory <chr>, type <chr>, subtype <chr>,
#> #   standard_popup_text <chr>, event_url <chr>, event_info <chr>, …

This data frame, with variables described in the API documentation, includes 1 row per event. We can normalize this to daily displacement, assuming uniform distribution of displacement between start and end date, for all countries and type of displacement. idmc_transform_daily().

idmc_transform_daily(df)
#> # A tibble: 922,896 × 5
#>    iso3  country    displacement_type date       displacement_daily
#>    <chr> <chr>      <chr>             <date>                  <dbl>
#>  1 AB9   Abyei Area Conflict          2018-01-01                  0
#>  2 AB9   Abyei Area Conflict          2018-01-02                  0
#>  3 AB9   Abyei Area Conflict          2018-01-03                  0
#>  4 AB9   Abyei Area Conflict          2018-01-04                  0
#>  5 AB9   Abyei Area Conflict          2018-01-05                  0
#>  6 AB9   Abyei Area Conflict          2018-01-06                  0
#>  7 AB9   Abyei Area Conflict          2018-01-07                  0
#>  8 AB9   Abyei Area Conflict          2018-01-08                  0
#>  9 AB9   Abyei Area Conflict          2018-01-09                  0
#> 10 AB9   Abyei Area Conflict          2018-01-10                  0
#> # ℹ 922,886 more rows

While there are a few other parameters you can play around with in these functions, this is the primary purpose of this simple package.