The retrieve data functions are based on the OxCGRT’s JSON API described here. Two API endpoints are provided: 1) endpoint for JSON providing data for stringency index by country over time; and, 2) endpoint for JSON providing data on policy actions and stringency index for a specific country on a specific day.

Stringency index by country over time

The first API endpoint provides JSON for all countries included in the OxCGRT over a specified period of time:


https://covidtrackerapi.bsg.ox.ac.uk/api/v2/stringency/date-range/{start-date}/{end-date}


where start-date and end-date are the starting date and ending date (both in YYYY-MM-DD format) respectively from which to retrieve data.

The oxcgrt package provides a function named get_json_time to interface with the API and retrieve the specified JSON and a function named get_data_time to extract the data from the specified JSON into an R tibble object. These two functions have been designed such that they can be piped from one to the other. Hence to retrieve stringency index data for all countries from 1 June 2020 to current date, the following code can be used:

get_json_time(from = "2020-06-01") %>% get_data_time()

This produces the following output:

#> # A tibble: 121,658 × 9
#>    date_value country_code country_name        confirmed deaths stringency_actu…
#>    <date>     <chr>        <chr>                   <int>  <int>            <dbl>
#>  1 2020-06-01 FIN          Finland                  6986    305             44.4
#>  2 2020-06-01 DNK          Denmark                 11699    576             60.2
#>  3 2020-06-01 LBN          Lebanon                  1233     27             74.1
#>  4 2020-06-01 GUY          Guyana                    153     12             87.0
#>  5 2020-06-01 PSE          Palestinian Territ…       449      3             80.6
#>  6 2020-06-01 AFG          Afghanistan             15836    269             84.3
#>  7 2020-06-01 SVK          Slovakia                 1522     28             67.6
#>  8 2020-06-01 VEN          Venezuela                1662     17             85.2
#>  9 2020-06-01 HKG          Hong Kong SAR China      1087      4             52.8
#> 10 2020-06-01 VNM          Vietnam                   328      0             69.4
#> # … with 121,648 more rows, and 3 more variables: stringency <dbl>,
#> #   stringency_legacy <dbl>, stringency_legacy_disp <dbl>

Important to note that in get_json_time, only the starting date (using the from argument) is specified to the desired 1 June 2020 in YYYY-MM-DD format. This is because by default the to argument (for the ending date) is set to the current date using a call to the Sys.Date() function. By default, the from argument is set to 2 January 2020 (2020-01-02) which is the earliest available data point for the stringency index. Therefore, to retrieve data on stringency index for all countries for all available time points up to current, the following commands can be issued:

which produces the following output:

#> # A tibble: 149,593 × 9
#>    date_value country_code country_name            stringency_actual stringency
#>    <date>     <chr>        <chr>                               <dbl>      <dbl>
#>  1 2020-01-02 FIN          Finland                               0          0  
#>  2 2020-01-02 DNK          Denmark                               0          0  
#>  3 2020-01-02 LBN          Lebanon                               0          0  
#>  4 2020-01-02 GUY          Guyana                                0          0  
#>  5 2020-01-02 PSE          Palestinian Territories               0          0  
#>  6 2020-01-02 AFG          Afghanistan                           0          0  
#>  7 2020-01-02 SVK          Slovakia                              0          0  
#>  8 2020-01-02 VEN          Venezuela                             0          0  
#>  9 2020-01-02 HKG          Hong Kong SAR China                  13.9       13.9
#> 10 2020-01-02 VNM          Vietnam                               0          0  
#> # … with 149,583 more rows, and 4 more variables: stringency_legacy <dbl>,
#> #   stringency_legacy_disp <dbl>, confirmed <int>, deaths <int>

Policy actions and stringency index for specific country on a specific day

The second API endpoint provides JSON for a specific country included in the OxCGRT for a specified day:


https://covidtrackerapi.bsg.ox.ac.uk/api/v2/stringency/actions/{country-code}/{date}


where country-code is the ISO 3166-1 alpha-3 country code for the required country to get data for and date is the date (in YYYY-MM-DD format) on which to retrieve data.

The oxcgrt package provides a function named get_json_actions to interface with the API and retrieve the specified JSON and a function named get_data to extract the data from the specified JSON into a named list R object. These two functions have been designed such that they can be piped from one to the other. Hence to retrieve policy actions and stringency index data for Afghanistan for 1 June 2020, the following code can be used:

get_json_actions(ccode = "AFG", 
                 from = NULL, 
                 to = "2020-06-01") %>% 
  get_data()

which produces the following output:

#> $policyActions
#> # A tibble: 23 × 9
#>    policy_type_code policy_type_display     policyvalue policyvalue_act… flagged
#>    <chr>            <chr>                         <int>            <int> <lgl>  
#>  1 C1               School closing                    3                3 TRUE   
#>  2 C2               Workplace closing                 3                3 FALSE  
#>  3 C3               Cancel public events              2                2 TRUE   
#>  4 C4               Restrictions on gather…           4                4 TRUE   
#>  5 C5               Close public transport            2                2 FALSE  
#>  6 C6               Stay at home requireme…           2                2 FALSE  
#>  7 C7               Restrictions on intern…           2                2 FALSE  
#>  8 C8               International travel c…           3                3 NA     
#>  9 E1               Income support                    0                0 NA     
#> 10 E2               Debt/contract relief              0                0 NA     
#> # … with 13 more rows, and 4 more variables: is_general <lgl>, notes <chr>,
#> #   flag_value_display_field <chr>, policy_value_display_field <chr>
#> 
#> $stringencyData
#> # A tibble: 1 × 6
#>   date_value country_code confirmed deaths stringency_actual stringency
#>   <chr>      <chr>            <int>  <int>             <dbl>      <dbl>
#> 1 2020-06-01 AFG              15836    269              84.3       84.3

Important to note that the output is a named list object containing a tibble of policy actions data and a tibble of stringency index data for the specified country and the specified date.

Policy actions for specific country or countries on a specific day or days

It is also possible to retrieve just policy actions data for a specific country or for multiple countries on a specific day or multiple days. To retrieve policy actions data for Afghanistan for 1 June 2020, the following code can be used:

get_json_actions(ccode = "AFG", 
                 from = NULL, 
                 to = "2020-06-01") %>% 
  get_data_action()

This results in:

#> # A tibble: 23 × 12
#>    date_value country_code country_name policy_type_code policy_type_display    
#>    <date>     <chr>        <chr>        <chr>            <chr>                  
#>  1 2020-06-01 AFG          Afghanistan  C1               School closing         
#>  2 2020-06-01 AFG          Afghanistan  C2               Workplace closing      
#>  3 2020-06-01 AFG          Afghanistan  C3               Cancel public events   
#>  4 2020-06-01 AFG          Afghanistan  C4               Restrictions on gather…
#>  5 2020-06-01 AFG          Afghanistan  C5               Close public transport 
#>  6 2020-06-01 AFG          Afghanistan  C6               Stay at home requireme…
#>  7 2020-06-01 AFG          Afghanistan  C7               Restrictions on intern…
#>  8 2020-06-01 AFG          Afghanistan  C8               International travel c…
#>  9 2020-06-01 AFG          Afghanistan  E1               Income support         
#> 10 2020-06-01 AFG          Afghanistan  E2               Debt/contract relief   
#> # … with 13 more rows, and 7 more variables: policyvalue <int>,
#> #   policyvalue_actual <int>, flagged <lgl>, is_general <lgl>, notes <chr>,
#> #   flag_value_display_field <chr>, policy_value_display_field <chr>

Important to note here that the output is a tibble of just the policy actions and three additional columns have been added to the dataset - date_value, country_code, and country_name - to identify the data as coming from a specific date and for a specific country.

To retrieve policy actions data for multiple countries on multiple days, the get_data_actions functions can be used as shown below:

get_json_actions(ccode = c("AFG", "Philippines"), 
                 from = "2020-10-25", 
                 to = "2020-10-31") %>% 
  get_data_actions()

This results in:

#> # A tibble: 322 × 12
#>    date_value country_code country_name policy_type_code policy_type_display    
#>    <date>     <chr>        <chr>        <chr>            <chr>                  
#>  1 2020-10-25 AFG          Afghanistan  C1               School closing         
#>  2 2020-10-25 AFG          Afghanistan  C2               Workplace closing      
#>  3 2020-10-25 AFG          Afghanistan  C3               Cancel public events   
#>  4 2020-10-25 AFG          Afghanistan  C4               Restrictions on gather…
#>  5 2020-10-25 AFG          Afghanistan  C5               Close public transport 
#>  6 2020-10-25 AFG          Afghanistan  C6               Stay at home requireme…
#>  7 2020-10-25 AFG          Afghanistan  C7               Restrictions on intern…
#>  8 2020-10-25 AFG          Afghanistan  C8               International travel c…
#>  9 2020-10-25 AFG          Afghanistan  E1               Income support         
#> 10 2020-10-25 AFG          Afghanistan  E2               Debt/contract relief   
#> # … with 312 more rows, and 7 more variables: policyvalue <int>,
#> #   policyvalue_actual <int>, flagged <lgl>, is_general <lgl>, notes <chr>,
#> #   flag_value_display_field <chr>, policy_value_display_field <chr>

Important to note here that the output is a tibble of just the policy actions and three additional columns have been added to the dataset - date_value, country_code, and country_name - to identify the data as coming from a specific date and for a specific country.