Skip to content

Minor lints #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions R/check.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ check_string_param <- function(name, value, required = TRUE) {
}

check_int_param <- function(name, value, required = TRUE) {
# string or string[]
# numeric or numeric[]
if ((required &&
!(!is.null(value) &&
is.numeric(value))) ||
Expand All @@ -23,24 +23,24 @@ check_int_param <- function(name, value, required = TRUE) {
}

is_epirange_like <- function(value) {
# character or numeric or EpiRange or list(from=..., to=...)
is.character(value) ||
is.numeric(value) ||
inherits(value, "EpiRange") ||
(is.list(value) &&
"from" %in% names(value) && "to" %in% names(value))
}

check_single_epirange_param <-
function(name, value, required = TRUE) {
if ((required &&
!(!is.null(value) &&
is_epirange_like(value))) ||
(!required && !(is.null(value) || is_epirange_like(value)))) {
rlang::abort(paste0("argument ", name, " is not a epirange"),
name = name, value = value, class = "invalid_argument"
)
}
check_single_epirange_param <- function(name, value, required = TRUE) {
if ((required &&
!(!is.null(value) &&
is_epirange_like(value))) ||
(!required && !(is.null(value) || is_epirange_like(value)))) {
rlang::abort(paste0("argument ", name, " is not a epirange"),
name = name, value = value, class = "invalid_argument"
)
}
}

check_epirange_param <- function(name, value, required = TRUE) {
if (is.null(value)) {
Expand Down
2 changes: 0 additions & 2 deletions R/constants.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


version <- "1.0.0"
http_headers <- httr::add_headers("User-Agent" = paste0("delphi_epidata", version))
global_base_url <- "https://delphi.cmu.edu/epidata/"
7 changes: 0 additions & 7 deletions R/covidcast.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

parse_signal <- function(signal, base_url) {
class(signal) <- c("covidcast_data_signal", class(signal))
signal$key <- paste(signal$source, signal$signal, sep = ":")

#'
#' fetch covidcast data
#'
#' @param data_source data source to fetch
Expand Down Expand Up @@ -48,7 +46,6 @@ parse_source <- function(source, base_url) {
r
}


as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
as.data.frame(do.call(rbind, lapply(signals, function(x) {
sub <- x[c(
Expand Down Expand Up @@ -77,7 +74,6 @@ as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
}), ...)
}


print.covidcast_data_source <- function(source, ...) {
print(source$name, ...)
print(source$source, ...)
Expand All @@ -86,13 +82,11 @@ print.covidcast_data_source <- function(source, ...) {
print(signals[, c("signal", "name", "short_description")], ...)
}

#'
#' creates the covidcast epidata helper
#'
#' @param base_url optional alternative base url
#' @importFrom httr RETRY stop_for_status content
#' @importFrom jsonlite fromJSON
#' @importFrom rlang abort
#' @return an instance of covidcast_epidata
#'
#' @export
Expand Down Expand Up @@ -122,7 +116,6 @@ covidcast_epidata <- function(base_url = global_base_url) {
)
}


as.data.frame.covidcast_data_source_list <- function(sources, ...) {
as.data.frame(do.call(rbind, lapply(sources, function(x) {
sub <- x[c(
Expand Down
11 changes: 0 additions & 11 deletions R/epidatacall.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@



create_epidata_call <- function(endpoint, params, meta = NULL,
only_supports_classic = FALSE) {
stopifnot(is.character(endpoint), length(endpoint) == 1)
Expand All @@ -22,7 +19,6 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
)
}

#'
#' use a different base url
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -66,7 +62,6 @@ full_url <- function(epidata_call) {
join_url(epidata_call$base_url, epidata_call$endpoint)
}

#'
#' returns the full request url for the given epidata_call
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -99,7 +94,6 @@ request_impl <- function(epidata_call, format_type, fields = NULL) {
do_request(url, params)
}

#'
#' fetches the data and returns the classic format
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -128,7 +122,6 @@ fetch_classic <- function(epidata_call, fields = NULL, disable_date_parsing = FA
m
}

#'
#' fetches the data and returns the josn format
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -156,7 +149,6 @@ fetch_json <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE
parse_data_frame(epidata_call, jsonlite::fromJSON(r), disable_date_parsing = disable_date_parsing)
}

#'
#' fetches the data and returns the CSV text
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -215,7 +207,6 @@ info_to_type <- function(info, disable_date_parsing = FALSE) {
r
}

#'
#' fetches the data and returns data frame
#'
#' @param epidata_call and instance of epidata_call
Expand Down Expand Up @@ -269,8 +260,6 @@ fetch_tbl <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE)
tbl
}


#'
#' fetches the data and returns data frame
#'
#' @param epidata_call and instance of epidata_call
Expand Down
62 changes: 29 additions & 33 deletions R/model.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@


#'
#' builds a new EpiRange instances
#'
#' @param from start
Expand All @@ -21,36 +18,35 @@ epirange <- function(from, to) {
structure(list(from = from, to = to), class = "EpiRange")
}

create_epidata_field_info <-
function(name,
type,
description = "",
categories = c()) {
stopifnot(is.character(name) && length(name) == 1)
stopifnot(
is.character(type) &&
length(type) == 1 &&
type %in% c(
"text",
"int",
"float",
"date",
"epiweek",
"categorical",
"bool"
)
)
stopifnot(is.character(description) && length(description) == 1)
structure(
list(
name = name,
type = type,
description = description,
categories = categories
),
class = "EpidataFieldInfo"
)
}
create_epidata_field_info <- function(name,
type,
description = "",
categories = c()) {
stopifnot(is.character(name) && length(name) == 1)
stopifnot(
is.character(type) &&
length(type) == 1 &&
type %in% c(
"text",
"int",
"float",
"date",
"epiweek",
"categorical",
"bool"
)
)
stopifnot(is.character(description) && length(description) == 1)
structure(
list(
name = name,
type = type,
description = description,
categories = categories
),
class = "EpidataFieldInfo"
)
}

parse_value <- function(info, value, disable_date_parsing = FALSE) {
stopifnot(inherits(info, "EpidataFieldInfo"))
Expand Down
4 changes: 0 additions & 4 deletions R/parse.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@

parse_api_date <- function(value) {
as.Date(as.character(value), format = "%Y%m%d")
}



#'
#' parses a week
#' @importFrom MMWRweek MMWRweek2Date
#' @return a date
Expand Down
1 change: 0 additions & 1 deletion R/request.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ join_url <- function(url, endpoint) {
paste0(url, endpoint)
}

#'
#' performs the request
#' @importFrom httr RETRY
do_request <- function(url, params) {
Expand Down
2 changes: 0 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


# Helper function to cast values and/or ranges to strings
format_item <- function(value) {
if (inherits(value, "EpiRange")) {
Expand Down