Skip to content

Commit

Permalink
converting air ticket prices to numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Oct 11, 2024
1 parent 6b99051 commit 6b58d45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/read_airfares.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ read_airfares <- function(date = 202001,
# check if download failed
if (is.null(dt)) { return(invisible(NULL)) }

# convert columns to numeric
convert_to_numeric(dt)

# clean names
nnn <- names(dt)
data.table::setnames(
Expand All @@ -72,6 +69,9 @@ read_airfares <- function(date = 202001,
new = janitor::make_clean_names(nnn)
)

# convert columns to numeric
convert_to_numeric(dt, type='airfare')

return(dt)
}

7 changes: 6 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,17 @@ altitude_to_numeric <- function(df){ # nocov start


#' @keywords internal
convert_to_numeric <- function(dt) {
convert_to_numeric <- function(dt, type=NULL) {

# detect if there are any columns that should be numeric
numeric_cols <- names(dt)[names(dt) %like% 'NR_|nr_']
numeric_cols <- numeric_cols[numeric_cols != 'nr_singular']

if (type=='airfare') {
arifa_col <- c('tarifa_n', 'tarifa')[c('tarifa_n', 'tarifa') %in% names(dt)]
numeric_cols <- c(numeric_cols, arifa_col)
}

if (length(numeric_cols)==0) { return(invisible(TRUE)) }

# replace , with . for numbers
Expand Down
18 changes: 18 additions & 0 deletions man/altitude_to_numeric.Rd

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

0 comments on commit 6b58d45

Please sign in to comment.