Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#149 - metadata order column to numeric #155

Merged
merged 2 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 5 additions & 6 deletions R/format.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
#' )
#'
#' adsl <- xportr_format(adsl, metadata)
xportr_format <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
xportr_format <- function(.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
Expand Down
11 changes: 5 additions & 6 deletions R/label.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
#' )
#'
#' adsl <- xportr_label(adsl, metadata)
xportr_label <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
xportr_label <- function(.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
Expand Down
11 changes: 5 additions & 6 deletions R/length.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@
#' )
#'
#' adsl <- xportr_length(adsl, metadata)
xportr_length <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
xportr_length <- function(.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
Expand Down
12 changes: 6 additions & 6 deletions R/order.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@
#' )
#'
#' adsl <- xportr_order(adsl, metadata)
xportr_order <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
xportr_order <- function(.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
Expand Down Expand Up @@ -69,6 +68,7 @@ xportr_order <- function(

# 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
11 changes: 5 additions & 6 deletions R/type.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@
#' )
#'
#' df2 <- xportr_type(.df, metadata, "test")
xportr_type <- function(
.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
xportr_type <- function(.df,
metadata = NULL,
domain = NULL,
verbose = getOption("xportr.length_verbose", "none"),
metacore = deprecated()) {
if (!missing(metacore)) {
lifecycle::deprecate_warn(
when = "0.3.0",
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)
})