Skip to content

Commit

Permalink
fix numeric cols in airfares
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapereirabr committed Oct 11, 2024
1 parent 6b58d45 commit 52d66c7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* Function `read_airports()` now downloads v2 version of public airports data. Closes [#41](https://github.com/ipeaGIT/flightsbr/issues/41)

* Major changes:
* Function `read_airfares()` is working again. Closes [#30](https://github.com/ipeaGIT/flightsbr/issues/30)
* Function `read_airfares()` is working again. Closes [#30](https://github.com/ipeaGIT/flightsbr/issues/30). The prices of air tickets are now returned as numeric.
* Function `read_flights()` with fixed decimal values in numeric columns. Closes [#43](https://github.com/ipeaGIT/flightsbr/issues/43)
* Function `read_airports()` with fixed values for `"altitude"` column. Closes [#42](https://github.com/ipeaGIT/flightsbr/issues/42)
* Function `read_airports()` with fixed numeric values for `"altitude"` column. Closes [#42](https://github.com/ipeaGIT/flightsbr/issues/42)

* Minor changes:
* Internally check of the consistency of date inputs. The date input must be consistent in either a 6-digit format `yyyymm` OR a 4-digit format `yyyy`.
Expand Down
10 changes: 6 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,19 @@ altitude_to_numeric <- function(df){ # nocov start


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

# 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 (type =='airfare') {
airfare_num_cols <- c('ano', 'mes', 'tarifa_n', 'tarifa', 'assentos')
airfare_num_cols <- airfare_num_cols[airfare_num_cols %in% names(dt)]
numeric_cols <- c(numeric_cols, airfare_num_cols)
}


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

# replace , with . for numbers
Expand Down

0 comments on commit 52d66c7

Please sign in to comment.