Skip to content

Commit

Permalink
docs: #84 merge in devel
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'origin/devel' into 84_xportr_deep_dive_vignette
# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
  • Loading branch information
bms63 committed Jun 11, 2023
2 parents a51bbbe + 8006e16 commit bea320e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Fixed bug where character_types were case sensitive. They are now case insensitive.
* Updated `xportr_type()` to make type coercion more explicit.
* Added function `xportr_metadata()` to explicitly set metadata at the start of a pipeline (#44)
* Metadata order columns are now coerced to numeric by default in `xportr_order()` to prevent character sorting (#149)

## Documentation

Expand Down
1 change: 1 addition & 0 deletions R/order.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ xportr_order <- function(.df,

# Grabs vars from Spec and inputted dataset
vars_in_spec_ds <- metadata[, c(variable_name, order_name)] %>%
mutate(!!sym(order_name) := as.numeric(!!sym(order_name))) %>%
arrange(!!sym(order_name)) %>%
extract2(variable_name)

Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-order.R
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,16 @@ test_that("xportr_order: Variable ordering messaging is correct", {
)
)
})

test_that("xportr_order: Metadata order columns are coersed to numeric", {
df <- data.frame(c = 1:5, a = "a", d = 5:1, b = LETTERS[1:5])
df_meta <- data.frame(
dataset = "df",
variable = letters[1:4],
order = c("1", "2", "11", "90")
)

ordered_df <- xportr_order(df, df_meta)

expect_equal(names(ordered_df), df_meta$variable)
})

0 comments on commit bea320e

Please sign in to comment.