From 16bc6427f281aa4ec7933c55fabd41df91e30155 Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Fri, 18 Oct 2024 17:06:49 +0000 Subject: [PATCH 1/2] Resolve #275 --- R/type.R | 4 ++-- tests/testthat/test-type.R | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/R/type.R b/R/type.R index 6ad58c2c..3a6e7015 100644 --- a/R/type.R +++ b/R/type.R @@ -117,7 +117,7 @@ xportr_type <- function(.df, } metacore <- metadata %>% - select(!!sym(variable_name), !!sym(type_name)) + select(variable = !!sym(variable_name), type = !!sym(type_name)) # Common check for multiple variables name check_multiple_var_specs(metadata, variable_name) @@ -128,7 +128,7 @@ xportr_type <- function(.df, # Produces a data.frame with Variables, Type.x(Table), and Type.y(metadata) meta_ordered <- left_join( data.frame(variable = names(.df), type = unlist(table_cols_types)), - metadata, + metacore, by = "variable" ) %>% mutate( diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index fec148ec..84f032a5 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -325,3 +325,24 @@ test_that("type Test 11: Works as expected with only one domain in metadata", { expect_equal(xportr_type(adsl, metadata), adsl) }) + +# xportr_type ---- +## Test 12: xportr_type: xportr_options() overrides work properly ---- +test_that("type Test 12: xportr_options() overrides work properly", { + op <- options() + + data("adsl_xportr", "var_spec", package = "xportr") + var_spec <- distinct(var_spec, Variable, .keep_all = TRUE) # quick fix because there's dups in the data + + xportr_options( + xportr.variable_name = "Variable", + xportr.type_name = "Data Type" + ) + + expect_silent( + adsl_xportr %>% xportr_type(var_spec, "ADSL", "message") + ) + + options(op) +}) + From 347cd7df478e0eaed61ed297caf010177f74aead Mon Sep 17 00:00:00 2001 From: "mike.stackhouse" Date: Fri, 18 Oct 2024 17:55:19 +0000 Subject: [PATCH 2/2] lint --- tests/testthat/test-type.R | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/testthat/test-type.R b/tests/testthat/test-type.R index 84f032a5..a8fba6dd 100644 --- a/tests/testthat/test-type.R +++ b/tests/testthat/test-type.R @@ -345,4 +345,3 @@ test_that("type Test 12: xportr_options() overrides work properly", { options(op) }) -