Skip to content

Commit

Permalink
CRAN v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
saudiwin committed Jul 21, 2022
1 parent 8c53761 commit 4a85021
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 51 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
^.*\.Rproj$
^\.Rproj\.user$
^README\.Rmd$
^CRAN-SUBMISSION$
^cran-comments\.md$
^LICENSE\.md$
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 0.3.0
Date: 2022-07-21 18:37:01 UTC
SHA: 8c537616765cdf5d6d3ef404762b0b2322406ac9
13 changes: 7 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: CoronaNetR
Type: Package
Title: API Access to CoronaNet Data
Title: API Access to 'CoronaNet' Data
Version: 0.3.0
Authors@R:
c(person(given = "Timothy",
Expand All @@ -13,18 +13,19 @@ Authors@R:
email="[email protected]",
comment = c(ORCID = "0000-0001-6655-4119")))
Maintainer: Robert Kubinec <[email protected]>
Description: CoronaNetR is a database on government responses to the COVID-19 pandemic.
To date, this dataset provides the most comprehensive and granular
Description: Offers access to a database on government responses to the COVID-19 pandemic.
To date, the 'CoronaNet' dataset provides the most comprehensive and granular
documentation of such government policies in the world, capturing data for
20 broad policy categories alongside many other dimensions, including the
initiator, target, and timing of a policy. This package is a programmatic
front-end to up-to-date CoronaNet data and the CoronaNet policy intensity index scores.
For more information, see Cheng et al. (2020) <doi:10.1038/s41562-020-0909-7>.
front-end to up-to-date 'CoronaNet' policy records and the 'CoronaNet' policy intensity index scores.
For more information, see 'Cheng et al.' (2020) <doi:10.1038/s41562-020-0909-7>.
License: MIT + file LICENSE
Depends:
R (>= 2.10)
Imports:
httr
httr,
R.utils
Encoding: UTF-8
Language: en-US
LazyData: true
Expand Down
23 changes: 2 additions & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,2 @@
MIT License

Copyright (c) 2022 CoronaNet Data Science

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
YEAR: 2022
COPYRIGHT HOLDER: Robert Kubinec
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2022 Robert Kubinec

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 82 additions & 16 deletions R/functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
#' @param to A character vector for the last end date, e.g., "2019-06-01".
#' @param include_no_end_date TRUE/FALSE - whether to include policy records that do not yet have an end date.
#' By default set to TRUE (this is a lot of records).
#' @param time_out Whether to set a 5-second time-out on the API call. Beyond 5 seconds, the function
#' will return an empty data-frame. Only useful for complying with CRAN
#' submission requirements. Default is FALSE.
#'
#' @return A dataframe with one record per COVID-19 policy
#' @export
#' @import httr
#' @importFrom utils URLencode
#' @importFrom R.utils withTimeout
#' @examples
#' # Grab all data for Saudi Arabia from first 4 months of pandemic
#'
Expand Down Expand Up @@ -77,7 +81,8 @@ get_event <- function(countries = "All",
additional_columns = NULL,
from = "2019-12-31",
to = "2022-01-01",
include_no_end_date=TRUE) {
include_no_end_date=TRUE,
time_out=FALSE) {

# Errors/Warnings ----

Expand Down Expand Up @@ -168,11 +173,40 @@ get_event <- function(countries = "All",

prod_query <- paste0(c(columns,date_filter,type,type_sub_cat,countries), collapse="&")

cor_query <- GET(URLencode(paste0("postgrest-1572524110.us-east-2.elb.amazonaws.com/public_release_allvars?",
prod_query)),
add_headers(Accept="text/csv"))
if(time_out) {

cor_query <- try(withTimeout(GET(URLencode(paste0("http://postgrest-1572524110.us-east-2.elb.amazonaws.com/public_release_allvars?",
prod_query)),
add_headers(Accept="text/csv")),
substitute=TRUE,
timeout=9,
onTimeout="silent"),
silent=TRUE)

if(!('try-error' %in% class(cor_query))) {


coronanet <- content(cor_query,type="text/csv",encoding="UTF-8")

} else {

print("API 10-second time-out reached.")

coronanet <- data.frame()

}

} else {

cor_query <- GET(URLencode(paste0("http://postgrest-1572524110.us-east-2.elb.amazonaws.com/public_release_allvars?",
prod_query)),
add_headers(Accept="text/csv"))

coronanet <- content(cor_query,type="text/csv",encoding="UTF-8")

}


coronanet <- content(cor_query,type="text/csv",encoding="UTF-8")

# Return all-country coronanet data
return(coronanet)
Expand Down Expand Up @@ -456,25 +490,31 @@ get_event <- function(countries = "All",
#' @param to The end time period in YYYY-MM-DD format. At present the index goes until 04-29-2021.
#' @param scaled Whether to use scores that are scaled between 0 and 100. By default FALSE. Only use
#' scaled scores for description and visualization, not inference/modeling.
#' @param time_out Whether to set a 5-second time-out on the API call. Beyond 5 seconds, the function
#' will return an empty data-frame. Only useful for complying with CRAN
#' submission requirements. Default is FALSE.
#' @export
#' @examples
#' # Download policy intensity scores of all types for all countries
#'
#' policy_scores <- get_policy_scores()
#'
#' # Download policy intensity scores for Japan and China
#'
#' japan_scores <- get_policy_scores(countries=c("Japan","China"))
#' japan_scores <- get_policy_scores(countries=c("Japan","China"),
#' from="2020-01-01",
#' to="2020-01-05",
#' time_out=TRUE)
#'
#' # Get scaled scores (0 to 100)
#'
#' japan_scores_scaled <- get_policy_scores(countries=c("Japan","China"),
#' scaled=TRUE)
#' from="2020-01-01",
#' to="2020-01-05",
#' scaled=TRUE,
#' time_out=TRUE)
get_policy_scores <- function(countries = "All",
type = "All",
from = "2019-12-31",
to = "2021-07-01",
scaled=FALSE) {
scaled=FALSE,
time_out=FALSE) {


if(scaled) {
Expand Down Expand Up @@ -532,11 +572,37 @@ get_policy_scores <- function(countries = "All",

prod_query <- paste0(c(date_filter,type,countries), collapse="&")

score_query <- GET(URLencode(paste0("postgrest-1572524110.us-east-2.elb.amazonaws.com/", table,"?",
prod_query)),
add_headers(Accept="text/csv"))
if(time_out) {

score_query <- try(withTimeout(GET(URLencode(paste0("http://postgrest-1572524110.us-east-2.elb.amazonaws.com/", table,"?",
prod_query)),
add_headers(Accept="text/csv")),
substitute=TRUE,
timeout=9,
onTimeout="silent"),
silent=TRUE)

if(!('try-error' %in% class(score_query))) {

scores <- content(score_query,type="text/csv",encoding="UTF-8")

} else {

print("API 10-second time-out reached.")

scores <- content(score_query,type="text/csv",encoding="UTF-8")
scores <- data.frame()

}

} else {

score_query <- GET(URLencode(paste0("http://postgrest-1572524110.us-east-2.elb.amazonaws.com/", table,"?",
prod_query)),
add_headers(Accept="text/csv"))

scores <- content(score_query,type="text/csv",encoding="UTF-8")

}

# Return all-country coronanet data
return(scores)
Expand Down
11 changes: 11 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.

## Win-Builder (devel and release)

0 errors | 0 warnings | 1 note

* This is a new release.
7 changes: 6 additions & 1 deletion man/get_event.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 14 additions & 7 deletions man/get_policy_scores.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4a85021

Please sign in to comment.