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

Fix for dev dplyr #346

Merged
merged 7 commits into from
Feb 8, 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
2 changes: 1 addition & 1 deletion R/apply_footnote_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 119,7 @@ get_col_loc <- function(footnote_structure, .data, col_plan_vars, columns){
if(last(col_str) == span_lvl){
col_loc <- unite_df_to_data_names(col_loc_df, preselected_cols = c(), column_names = col_str)
if(!is.null(names(col_loc))){
col_loc <- if_else(names(col_loc) != "", names(col_loc), col_loc)
col_loc <- if_else(names(col_loc) != "", names(col_loc), unname(col_loc))
}
out <- list(col = col_loc, spanning = FALSE)
} else {
Expand Down
3 changes: 2 additions & 1 deletion R/apply_tfrmt.R
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 309,7 @@ pivot_wider_tfrmt <- function(data, tfrmt, mock){
map_chr(as_name)
tbl_dat_wide <- data %>%
select(-!!tfrmt$param) %>%
mutate(across(all_of(column_cols), as.character)) %>%
mutate(across(all_of(column_cols), na_if, "")) %>%
quietly(pivot_wider)(
names_from = c(starts_with(.tlang_struct_col_prefix), !!!tfrmt$column),
Expand All @@ -318,7 319,7 @@ pivot_wider_tfrmt <- function(data, tfrmt, mock){
)

if (mock == TRUE && length(tbl_dat_wide$warnings)>0 &&
str_detect(tbl_dat_wide$warnings, paste0("Values from `", as_label(tfrmt$value), "` are not uniquely identified"))){
any(str_detect(tbl_dat_wide$warnings, paste0("Values from `", as_label(tfrmt$value), "` are not uniquely identified")))){
message("Mock data contains more than 1 param per unique label value. Param values will appear in separate rows.")
tbl_dat_wide <- tbl_dat_wide$result %>%
unnest(cols = everything()) %>%
Expand Down
1 change: 1 addition & 0 deletions R/frmt_plans.R
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 181,7 @@ frmt_combine <- function(expression, ..., missing = NULL){

n_vars <- str_count(expression, everything_but_curly)
vars_to_fmt <- str_extract_all(expression, everything_but_curly, simplify = TRUE)
vars_to_fmt <- as.vector(vars_to_fmt)
frmt_ls <- list(...)

if(n_vars != length(frmt_ls) & length(frmt_ls) > 1){
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/_snaps/make_mock_data.md
Original file line number Diff line number Diff line change
@@ -0,0 1,7 @@
# Check mock when value is missing

Code
out <- print_mock_gt(plan, data)
Message <simpleMessage>
Message: `tfrmt` will need `value` value to `print_to_gt` when data is avaliable

12 changes: 7 additions & 5 deletions tests/testthat/test-make_mock_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 194,9 @@ test_that("Check mock when value is missing", {
)

#Make mock
quietly(print_mock_gt)(plan, data)$warnings %>%
expect_equal(character())
expect_snapshot(
out <- print_mock_gt(plan, data)
)
})


Expand Down Expand Up @@ -465,7 466,7 @@ test_that("Mock data can be made and printed without label",{
)

#Make mock
expect_silent(
expect_no_message(
print_mock_gt(plan, .data = dat)
)

Expand Down Expand Up @@ -539,10 540,11 @@ test_that("Using col_plan to get column names", {
)
) %>%
make_mock_data() %>%
select(test1, test2) %>%
distinct(test1, test2)

man_col_df <- tibble(test2 = c("col4","col3", "col5", "col1", "col2", "col7","col8"),
test1 = c(rep(NA, 3), rep(c("span 1", "span 2"), each = 2)))
man_col_df <- tibble(test1 = c(rep(NA, 3), rep(c("span 1", "span 2"), each = 2)),
test2 = c("col4","col3", "col5", "col1", "col2", "col7","col8"))
expect_equal(auto_col_df, man_col_df)


Expand Down