@@ -195,72 +195,6 @@ fetch_classic <- function(epidata_call, fields = NULL, disable_data_frame_parsin
195
195
return (response_content $ epidata )
196
196
}
197
197
198
- # ' Fetches the data and returns a tibble or an `epidata_csv`
199
- # '
200
- # ' @param epidata_call an instance of `epidata_call`
201
- # ' @param fields filter fields
202
- # ' @param disable_date_parsing Boolean. Optionally, `TRUE` to disable parsing of
203
- # ' columns we expect to be dates, keeping them as character columns instead.
204
- # ' `FALSE` (the default) to parse these columns into `Date` vectors.
205
- # ' @param disable_tibble_output Boolean. Optionally, `TRUE` to output a
206
- # ' character vector with the `epidata_csv` class (which provides a custom
207
- # ' `print` method). `FALSE` (the default) to output a tibble.
208
- # ' @return
209
- # ' - For `fetch_csv`: a tibble, or `epidata_csv` if requested with
210
- # ' `disable_tibble_output = TRUE`
211
- # '
212
- # ' @importFrom httr stop_for_status content
213
- # ' @importFrom rlang abort
214
- fetch_csv <- function (epidata_call , fields = NULL , disable_date_parsing = FALSE , disable_tibble_output = FALSE ) {
215
- stopifnot(inherits(epidata_call , " epidata_call" ))
216
- stopifnot(is.null(fields ) || is.character(fields ))
217
-
218
- if (epidata_call $ only_supports_classic ) {
219
- rlang :: abort(" This endpoint only supports the classic message format, due to a non-standard behavior. Use fetch_classic instead." ,
220
- epidata_call = epidata_call ,
221
- class = " only_supports_classic_format"
222
- )
223
- }
224
-
225
- response <- request_impl(epidata_call , " csv" , fields )
226
- response_content <- httr :: content(response , " text" , encoding = " UTF-8" )
227
- class(response_content ) <- c(" epidata_csv" , class(response_content ))
228
-
229
- if (disable_tibble_output ) {
230
- return (response_content )
231
- }
232
-
233
- meta <- epidata_call $ meta
234
- fields_pred <- fields_to_predicate(fields )
235
- col_names <- c()
236
- col_types <- list ()
237
- for (i in seq_len(length(meta ))) {
238
- info <- meta [[i ]]
239
- if (fields_pred(info $ name )) {
240
- col_names <- c(col_names , info $ name )
241
- col_types [info $ name ] <- info_to_type(info , disable_date_parsing )
242
- }
243
- }
244
-
245
- csv_tibble <- if (length(col_names ) > 0 ) {
246
- readr :: read_csv(response_content , col_types = col_types )
247
- } else {
248
- readr :: read_csv(response_content )
249
- }
250
-
251
- if (! disable_date_parsing ) {
252
- # parse weeks
253
- columns <- colnames(csv_tibble )
254
- for (i in seq_len(length(meta ))) {
255
- info <- meta [[i ]]
256
- if (info $ name %in% columns && info $ type == " epiweek" ) {
257
- csv_tibble [[info $ name ]] <- parse_api_week(csv_tibble [[info $ name ]])
258
- }
259
- }
260
- }
261
- csv_tibble
262
- }
263
-
264
198
fetch_debug <- function (epidata_call , format_type = " classic" , fields = NULL ) {
265
199
response <- request_impl(epidata_call , format_type , fields )
266
200
content <- httr :: content(response , " text" , encoding = " UTF-8" )
@@ -334,37 +268,3 @@ request_impl <- function(epidata_call, format_type, fields = NULL) {
334
268
335
269
response
336
270
}
337
-
338
- # ' @export
339
- print.epidata_csv <- function (x , ... ) {
340
- char_limit <- getOption(" epidata_csv__char_limit" , default = 300L )
341
- cat(
342
- " # A epidata_csv object with" , nchar(x ), " characters; showing up to" , char_limit ,
343
- " characters below. To print the entire string, use `print(as.character(x))`:\n "
344
- )
345
- cat(substr(x , 1L , char_limit ))
346
- if (nchar(x ) > char_limit ) {
347
- cat(" [...]" )
348
- }
349
- cat(" \n " )
350
- invisible (x )
351
- }
352
-
353
- info_to_type <- function (info , disable_date_parsing = FALSE ) {
354
- types <- list (
355
- date = if (disable_date_parsing ) {
356
- readr :: col_integer()
357
- } else {
358
- readr :: col_date(format = " %Y%m%d" )
359
- },
360
- epiweek = readr :: col_integer(),
361
- bool = readr :: col_logical(),
362
- text = readr :: col_character(),
363
- int = readr :: col_integer(),
364
- float = readr :: col_double(),
365
- categorical = readr :: col_factor(info $ categories )
366
- )
367
- r <- types [info $ type ]
368
- stopifnot(! is.null(r ))
369
- r
370
- }
0 commit comments