test-code/turf print.R

# Begin turf message ------------------------------------------------------

k.range <- range(k)

# nicer output for displaying k range
if (identical(seq(k.range[1], k.range[2], by = 1), k) & length(k) > 1) {
    k.string <- glue("{k.range[1]}-{k.range[2]}")
} else {
    k.string <- paste(k, collapse = ", ")
}

cat_line(rule("TURF", line = 2))
cat_line(style_italic(" Sample size: "), scales::comma(nrow(item.mat)))
cat_line(style_italic("  # of items: "), n.items)
cat_line(style_italic("   Set sizes: "), k.string)
cat_line(style_italic("       Depth: "), depth)

if (greedy_begin <= max(k)) {
    cat_line()
    cat_line(rule("Greedy Algorithm", line = 1))
    cat_line(style_italic("Begins at set size: "), greedy_begin)
    cat_line(style_italic("      Entry method: "), greedy_entry)
}
cat_line()

# Inclusion/exclusion messages --------------------------------------------

if (any(do.force.in, do.force.in.together, do.force.out, do.force.out.together)) {

    cat_line(rule("Constraints"))

    if (do.force.in) {
        msg <- paste(force.in.names, collapse = ", ")
        cat_line("Items included in every combination")
        cat_line(paste("\U2022", msg))
        cat_line()
    }

    if (do.force.in.together) {

        num <- length(force.in.together.names)

        msg <-
            force.in.together.names %>%
            map(paste, collapse = ", ") %>%
            map2(
                .x = .,
                .y = 1:num,
                .f = ~glue("\U2022 {.x}")
            ) %>%
            paste(collapse = "\n")

        cat_line("Items that must all appear together within a combination")
        cat_line(msg)
        cat_line()

    }

    if (do.force.out) {
        msg <- paste(force.out.names, collapse = ", ")
        cat_line("Items excluded from every combination")
        cat_line(paste("\U2022", msg))
        cat_line()
    }

    if (do.force.out.together) {

        num <- length(force.out.together.names)

        msg <-
            force.out.together.names %>%
            map(paste, collapse = ", ") %>%
            map2(
                .x = .,
                .y = 1:num,
                .f = ~glue("\U2022 {.x}")
            ) %>%
            paste(collapse = "\n")

        cat_line("Items that cannot all appear together within any combination")
        cat_line(msg)
        cat_line()

    }

}
ttrodrigz/onezero documentation built on May 9, 2023, 2:59 p.m.