It's an interesting problem. The starting point maybe to convert your order into a binary representation, do the same for your data. Merge the two and then arrange.
If I've understood correctly here is a subset example that shows what I mean:
library(tidyverse)
df <- tibble(col1 = sample(c(FALSE, TRUE), replace=TRUE, size=20),
col2 = sample(c(FALSE, TRUE), replace=TRUE, size=20),
col3 = sample(c(FALSE, TRUE), replace=TRUE, size=20),
col4 = sample(c(1,2), replace=TRUE, size=20),
col5 = sample(c("A", "B", "C"), replace=TRUE, size=20))
test_df <- tibble(tests = c("FFF1", "FFF2", "TFF1", "TFF2", "TTF1", "TTF2", "TFT1", "TFT2"))
test_df <- test_df %>%
rowwise() %>%
mutate(pos = 0) %>%
mutate(pos = ifelse(substring(tests, 1, 1) == "T", pos + 1, pos)) %>%
mutate(pos = ifelse(substring(tests, 2, 2) == "T", pos + 2, pos)) %>%
mutate(pos = ifelse(substring(tests, 3, 3) == "T", pos + 4, pos)) %>%
mutate(pos = ifelse(substring(tests, 4, 4) == 2, pos + 8, pos))
df <- df %>%
rowwise() %>%
mutate(pos = 0) %>%
mutate(pos = ifelse(col1 == TRUE, pos + 1, pos)) %>%
mutate(pos = ifelse(col2 == TRUE, pos + 2, pos)) %>%
mutate(pos = ifelse(col3 == TRUE, pos + 4, pos)) %>%
mutate(pos = ifelse(col4 == 2, pos + 8, pos))
left_join(test_df, df, by = join_by(pos == pos)) %>%
arrange(pos) %>%
select(-pos, -tests) %>%
na.omit()
Essentially this builds the dataframe and the tests. Then adds a column pos
for each test and then left_joins them before arranging.
Not very pretty, but should give what you're looking for?
col1 col2 col3 col4 col5
<lgl> <lgl> <lgl> <dbl> <chr>
1 FALSE FALSE FALSE 1 B
2 TRUE FALSE FALSE 1 A
3 TRUE TRUE FALSE 1 B
4 TRUE TRUE FALSE 1 B
5 TRUE TRUE FALSE 1 B
6 TRUE FALSE TRUE 1 B
7 TRUE TRUE FALSE 2 B