Skip to content

Commit b60bc02

Browse files
authored
Merge pull request #27 from cmu-delphi/ds/lint-pass
Minor lints
2 parents 0e9c7c9 + 447304c commit b60bc02

File tree

8 files changed

+40
-71
lines changed

8 files changed

+40
-71
lines changed

R/check.R

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ check_string_param <- function(name, value, required = TRUE) {
1111
}
1212

1313
check_int_param <- function(name, value, required = TRUE) {
14-
# string or string[]
14+
# numeric or numeric[]
1515
if ((required &&
1616
!(!is.null(value) &&
1717
is.numeric(value))) ||
@@ -23,24 +23,24 @@ check_int_param <- function(name, value, required = TRUE) {
2323
}
2424

2525
is_epirange_like <- function(value) {
26+
# character or numeric or EpiRange or list(from=..., to=...)
2627
is.character(value) ||
2728
is.numeric(value) ||
2829
inherits(value, "EpiRange") ||
2930
(is.list(value) &&
3031
"from" %in% names(value) && "to" %in% names(value))
3132
}
3233

33-
check_single_epirange_param <-
34-
function(name, value, required = TRUE) {
35-
if ((required &&
36-
!(!is.null(value) &&
37-
is_epirange_like(value))) ||
38-
(!required && !(is.null(value) || is_epirange_like(value)))) {
39-
rlang::abort(paste0("argument ", name, " is not a epirange"),
40-
name = name, value = value, class = "invalid_argument"
41-
)
42-
}
34+
check_single_epirange_param <- function(name, value, required = TRUE) {
35+
if ((required &&
36+
!(!is.null(value) &&
37+
is_epirange_like(value))) ||
38+
(!required && !(is.null(value) || is_epirange_like(value)))) {
39+
rlang::abort(paste0("argument ", name, " is not a epirange"),
40+
name = name, value = value, class = "invalid_argument"
41+
)
4342
}
43+
}
4444

4545
check_epirange_param <- function(name, value, required = TRUE) {
4646
if (is.null(value)) {

R/constants.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
version <- "1.0.0"
42
http_headers <- httr::add_headers("User-Agent" = paste0("delphi_epidata", version))
53
global_base_url <- "https://delphi.cmu.edu/epidata/"

R/covidcast.R

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
parse_signal <- function(signal, base_url) {
32
class(signal) <- c("covidcast_data_signal", class(signal))
43
signal$key <- paste(signal$source, signal$signal, sep = ":")
54

6-
#'
75
#' fetch covidcast data
86
#'
97
#' @param data_source data source to fetch
@@ -48,7 +46,6 @@ parse_source <- function(source, base_url) {
4846
r
4947
}
5048

51-
5249
as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
5350
as.data.frame(do.call(rbind, lapply(signals, function(x) {
5451
sub <- x[c(
@@ -77,7 +74,6 @@ as.data.frame.covidcast_data_signal_list <- function(signals, ...) {
7774
}), ...)
7875
}
7976

80-
8177
print.covidcast_data_source <- function(source, ...) {
8278
print(source$name, ...)
8379
print(source$source, ...)
@@ -86,13 +82,11 @@ print.covidcast_data_source <- function(source, ...) {
8682
print(signals[, c("signal", "name", "short_description")], ...)
8783
}
8884

89-
#'
9085
#' creates the covidcast epidata helper
9186
#'
9287
#' @param base_url optional alternative base url
9388
#' @importFrom httr RETRY stop_for_status content
9489
#' @importFrom jsonlite fromJSON
95-
#' @importFrom rlang abort
9690
#' @return an instance of covidcast_epidata
9791
#'
9892
#' @export
@@ -122,7 +116,6 @@ covidcast_epidata <- function(base_url = global_base_url) {
122116
)
123117
}
124118

125-
126119
as.data.frame.covidcast_data_source_list <- function(sources, ...) {
127120
as.data.frame(do.call(rbind, lapply(sources, function(x) {
128121
sub <- x[c(

R/epidatacall.R

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
41
create_epidata_call <- function(endpoint, params, meta = NULL,
52
only_supports_classic = FALSE) {
63
stopifnot(is.character(endpoint), length(endpoint) == 1)
@@ -22,7 +19,6 @@ create_epidata_call <- function(endpoint, params, meta = NULL,
2219
)
2320
}
2421

25-
#'
2622
#' use a different base url
2723
#'
2824
#' @param epidata_call and instance of epidata_call
@@ -66,7 +62,6 @@ full_url <- function(epidata_call) {
6662
join_url(epidata_call$base_url, epidata_call$endpoint)
6763
}
6864

69-
#'
7065
#' returns the full request url for the given epidata_call
7166
#'
7267
#' @param epidata_call and instance of epidata_call
@@ -99,7 +94,6 @@ request_impl <- function(epidata_call, format_type, fields = NULL) {
9994
do_request(url, params)
10095
}
10196

102-
#'
10397
#' fetches the data and returns the classic format
10498
#'
10599
#' @param epidata_call and instance of epidata_call
@@ -128,7 +122,6 @@ fetch_classic <- function(epidata_call, fields = NULL, disable_date_parsing = FA
128122
m
129123
}
130124

131-
#'
132125
#' fetches the data and returns the josn format
133126
#'
134127
#' @param epidata_call and instance of epidata_call
@@ -156,7 +149,6 @@ fetch_json <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE
156149
parse_data_frame(epidata_call, jsonlite::fromJSON(r), disable_date_parsing = disable_date_parsing)
157150
}
158151

159-
#'
160152
#' fetches the data and returns the CSV text
161153
#'
162154
#' @param epidata_call and instance of epidata_call
@@ -215,7 +207,6 @@ info_to_type <- function(info, disable_date_parsing = FALSE) {
215207
r
216208
}
217209

218-
#'
219210
#' fetches the data and returns data frame
220211
#'
221212
#' @param epidata_call and instance of epidata_call
@@ -269,8 +260,6 @@ fetch_tbl <- function(epidata_call, fields = NULL, disable_date_parsing = FALSE)
269260
tbl
270261
}
271262

272-
273-
#'
274263
#' fetches the data and returns data frame
275264
#'
276265
#' @param epidata_call and instance of epidata_call

R/model.R

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
2-
3-
#'
41
#' builds a new EpiRange instances
52
#'
63
#' @param from start
@@ -21,36 +18,35 @@ epirange <- function(from, to) {
2118
structure(list(from = from, to = to), class = "EpiRange")
2219
}
2320

24-
create_epidata_field_info <-
25-
function(name,
26-
type,
27-
description = "",
28-
categories = c()) {
29-
stopifnot(is.character(name) && length(name) == 1)
30-
stopifnot(
31-
is.character(type) &&
32-
length(type) == 1 &&
33-
type %in% c(
34-
"text",
35-
"int",
36-
"float",
37-
"date",
38-
"epiweek",
39-
"categorical",
40-
"bool"
41-
)
42-
)
43-
stopifnot(is.character(description) && length(description) == 1)
44-
structure(
45-
list(
46-
name = name,
47-
type = type,
48-
description = description,
49-
categories = categories
50-
),
51-
class = "EpidataFieldInfo"
52-
)
53-
}
21+
create_epidata_field_info <- function(name,
22+
type,
23+
description = "",
24+
categories = c()) {
25+
stopifnot(is.character(name) && length(name) == 1)
26+
stopifnot(
27+
is.character(type) &&
28+
length(type) == 1 &&
29+
type %in% c(
30+
"text",
31+
"int",
32+
"float",
33+
"date",
34+
"epiweek",
35+
"categorical",
36+
"bool"
37+
)
38+
)
39+
stopifnot(is.character(description) && length(description) == 1)
40+
structure(
41+
list(
42+
name = name,
43+
type = type,
44+
description = description,
45+
categories = categories
46+
),
47+
class = "EpidataFieldInfo"
48+
)
49+
}
5450

5551
parse_value <- function(info, value, disable_date_parsing = FALSE) {
5652
stopifnot(inherits(info, "EpidataFieldInfo"))

R/parse.R

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
21
parse_api_date <- function(value) {
32
as.Date(as.character(value), format = "%Y%m%d")
43
}
54

6-
7-
8-
#'
95
#' parses a week
106
#' @importFrom MMWRweek MMWRweek2Date
117
#' @return a date

R/request.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ join_url <- function(url, endpoint) {
55
paste0(url, endpoint)
66
}
77

8-
#'
98
#' performs the request
109
#' @importFrom httr RETRY
1110
do_request <- function(url, params) {

R/utils.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
# Helper function to cast values and/or ranges to strings
42
format_item <- function(value) {
53
if (inherits(value, "EpiRange")) {

0 commit comments

Comments
 (0)