I am attempting to print out a table that is organizing a set of measures for each activity. However, not all activities have a measure. However, while using packed_rows in the kableextra package, whenever the last category of the table only has one row in its group, the table combines it with the previous group. Does anyone know why it may be doing that?
The only thing that worked was moving the order of the rows so that “No Related Measure” was not the last row. However, I need to automate this code and run it 70+ times with different data and I can’t manually change the row order every time.
The groupings in the middle of the table are correct
The grouping for the last row of the table is incorrect
df_activities_agency <- df_activities %>%
filter(Agency == params$agency) %>%
select(-Agency) %>%
mutate(across(everything(), gsub, pattern = "[rn]", replacement = " "))
df_activities_agency$Activity <- paste0(df_activities_agency$`Activity Name`, ": ", df_activities_agency$`Activity Description`)
df_measures_act_agency <- df_measures |>
filter(Agency == params$agency) |>
mutate(across(everything(), gsub, pattern = "[rn]", replacement = " ")) |>
select(2,11,12)
names(df_measures_act_agency) <- c("Measure","Record ID", "Activity Title")
df_measures_act_tbl <- df_measures_act_agency %>% select(1)
df_act_joined <- left_join(df_activities_agency, df_measures_act_agency, by = "Record ID") %>%
select(1,2,5)
df_act_joined[is.na(df_act_joined)] <- "No Related Measures"
df_act_joined <- df_act_joined %>% arrange(`Record ID`)
df_act_joined_tbl <- df_act_joined %>% select(3)
activities_agency <- kbl(df_act_joined_tbl,
format = "latex",
booktabs = TRUE,
longtable = TRUE,
linesep = "\addlinespace",
col.names = NULL,
border = NULL) %>%
kable_styling(latex_options = c("repeat_header"),
position = "left",
full_width = FALSE,
font_size = 10,
stripe_color = "Snow2") %>%
pack_rows(index = table(fct_inorder(df_act_joined$`Activity Name`)),
latex_wrap_text = TRUE,
hline_after = TRUE,
latex_align = "l",
latex_gap_space = "1em") %>%
column_spec(1, width = "50em")
print(activities_agency)
Caro W. is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.