camr_assert_indicies
The following function is proposed for inclusion. Its purpose is to throw an error if a dataframe contains an unexpected number of index columns (starting with IDX
).
camr_assert_indicies <- function(df_data, int_indicies) {
assert_integer(int_indicies, lower=1L, any.missing=FALSE)
assert_data_frame(df_data, min.rows=int_indicies, col.names='named')
vint_idx_names <- colnames(df_data) |> str_detect('^IDX\\.') |> which()
vint_idx_not_at_start <-
vint_idx_names[!vint_idx_names %in% seq_along(vint_idx_names)]
if (length(vint_idx_names) != int_indicies)
cli_abort('Expected {substitute(df_data)} to have {int_indicies}
index column{?s} but {length(vint_idx_names)} were detected.')
if(length(vint_idx_not_at_start) > 0L)
cli_warn('Index columns {colnames(df_data)[vint_idx_not_at_start]}
of {substitute(df_data)} are not leftmost.')
df_data
}
@kp390 @be931 @lvn3 Let's test this workflow. If you have any suggestions, please leave them here. If we think this is good to include, you can leave a thumbs up and I will integrate on the issue's due date. (See the other issue too!)
Edited by Pascale, Michael Philip