Skip to content

Commit

Permalink
Add empty_cells and unused_pairs functions. (#19)
Browse files Browse the repository at this point in the history
MHenderson authored Jun 21, 2024
1 parent 298d4cb commit 0539022
Showing 6 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: wallis
Title: Room squares in R
Version: 0.0.0.9002
Version: 0.0.0.9003
Authors@R:
person("Matthew", "Henderson", , "matthew.james.henderson@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-7949-8208"))
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(empty_cells)
export(n_filled_cells)
export(plot_room_square)
export(unused_pairs)
export(volume)
11 changes: 11 additions & 0 deletions R/empty-cells.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#' Empty cells of a partial Room square
#'
#' @param R A partial Room square.
#'
#' @return A list of empty cells of R.
#' @export
empty_cells <- function(R) {
E <- R[is.na(R$first), ]
E <- mapply(c, E$row, E$col, SIMPLIFY = FALSE)
return(E)
}
24 changes: 24 additions & 0 deletions R/unused-pairs.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#' Pairs not used in a partial Room square
#'
#' @param R A partial Room square.
#'
#' @return A list of pairs not used in R.
#' @export
unused_pairs <- function(R) {

n <- max(R$row) + 1

used_pairs <- R |> dplyr::select(first, second)

x <- combn(0:(n - 1), 2)

all_pairs <- tibble::tibble(
first = x[1,],
second = x[2,]
)

dplyr::anti_join(all_pairs, used_pairs, by = c("first", "second")) |>
dplyr::mutate(ffs = purrr::map2(first, second, c)) |>
dplyr::pull(ffs)

}
17 changes: 17 additions & 0 deletions man/empty_cells.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions man/unused_pairs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0539022

Please sign in to comment.