Skip to content

Commit

Permalink
suppressWarnings() from vroom
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Sep 8, 2023
1 parent 0954140 commit 4f09b45
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
77 changes: 42 additions & 35 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -399,14 +399,16 @@ get_weather_for_station <- function(station, year, dir,
httr::stop_for_status(request)

# load the data, but fast !
weather_raw <- vroom::vroom(file = paste0(dir,
"/weather_",
station,
".csv"),
comment = "#",
na = "M",
col_names = TRUE,
col_types = weather_col_types)
suppressWarnings(
weather_raw <- vroom::vroom(file = paste0(dir,
"/weather_",
station,
".csv"),
comment = "#",
na = "M",
col_names = TRUE,
col_types = weather_col_types)
)

# delete the raw data
unlink(paste0(dir, "/weather_", station, ".csv"))
Expand Down Expand Up @@ -491,14 +493,14 @@ get_planes_data <- function(year, dir, flights_data) {


process_planes_master <- function(planes_lcl) {
suppressMessages(
suppressMessages(suppressWarnings(
# read in the data, but fast
planes_master <- vroom::vroom(paste0(planes_lcl, "/MASTER.txt"),
progress = FALSE) %>%
# the column names change every year, but the positions have stayed the
# same -- select by position :-(
dplyr::select(nnum = 1, code = 3, year = 5)
)
))

# delete the temporary folder
unlink(x = planes_lcl, recursive = TRUE)
Expand Down Expand Up @@ -531,15 +533,18 @@ process_planes_ref <- function(planes_lcl) {
utils::unzip(planes_tmp, exdir = planes_lcl, junkpaths = TRUE)

# read in the data, but fast
planes_ref <- vroom::vroom(paste0(planes_lcl,
"/",
"ACFTREF.txt"),
col_names = planes_ref_col_names,
col_types = planes_ref_col_types,
progress = FALSE,
skip = 1) %>%
dplyr::select(code, mfr, model, type_acft,
type_eng, no_eng, no_seats, speed)
suppressMessages(suppressWarnings(
planes_ref <- vroom::vroom(paste0(planes_lcl,
"/",
"ACFTREF.txt"),
col_names = planes_ref_col_names,
col_types = planes_ref_col_types,
progress = FALSE,
skip = 1) %>%
dplyr::select(code, mfr, model, type_acft,
type_eng, no_eng, no_seats, speed)
))


# delete the temporary folder
unlink(x = planes_lcl, recursive = TRUE)
Expand All @@ -548,22 +553,24 @@ process_planes_ref <- function(planes_lcl) {
}

join_planes_data <- function(planes_master, planes_ref) {
planes_master %>%
dplyr::inner_join(planes_ref, by = "code") %>%
dplyr::select(-code) %>%
dplyr::mutate(speed = dplyr::if_else(speed == 0, NA_character_, speed),
no_eng = dplyr::if_else(no_eng == 0, NA_integer_, no_eng),
no_seats = dplyr::if_else(no_seats == 0, NA_integer_, no_seats),
engine = engine_types[type_eng + 1],
type = acft_types[type_acft],
tailnum = paste0("N", nnum),
year = as.integer(year),
speed = as.integer(speed)) %>%
dplyr::rename(manufacturer = mfr,
engines = no_eng,
seats = no_seats) %>%
dplyr::select(tailnum, year, type, manufacturer, model, engines,
seats, speed, engine)
suppressWarnings(
planes_master %>%
dplyr::inner_join(planes_ref, by = "code") %>%
dplyr::select(-code) %>%
dplyr::mutate(speed = dplyr::if_else(speed == 0, NA_character_, speed),
no_eng = dplyr::if_else(no_eng == 0, NA_integer_, no_eng),
no_seats = dplyr::if_else(no_seats == 0, NA_integer_, no_seats),
engine = engine_types[type_eng + 1],
type = acft_types[type_acft],
tailnum = paste0("N", nnum),
year = as.integer(year),
speed = as.integer(speed)) %>%
dplyr::rename(manufacturer = mfr,
engines = no_eng,
seats = no_seats) %>%
dplyr::select(tailnum, year, type, manufacturer, model, engines,
seats, speed, engine)
)
}


Expand Down
3 changes: 0 additions & 3 deletions tests/testthat/test-6-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,5 @@ test_that("checking download file wrapper", {
expect_warning(expect_error(anyflights("LAX", 2020, 1),
"utils::download.file timed out before finishing downloading the file"
))
expect_warning(expect_error(get_planes(2018),
"utils::download.file timed out before finishing downloading the file"
))
options(timeout = original_timeout_value)
})

0 comments on commit 4f09b45

Please sign in to comment.