From 3a4065129785da65ab8cd79f5eebfb8dd99da987 Mon Sep 17 00:00:00 2001 From: Matthew Henderson Date: Wed, 29 May 2024 07:35:17 +0000 Subject: [PATCH] A customisable row extension function. --- DESCRIPTION | 2 +- R/add-rows.R | 15 +++++---------- man/add_rows.Rd | 7 +++---- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 463614b..b7a1ea6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: keedwell Title: Latin Squares in R -Version: 0.1.1.9001 +Version: 0.1.1.9002 Authors@R: person("Matthew", "Henderson", , "matthew.james.henderson@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-7949-8208")) diff --git a/R/add-rows.R b/R/add-rows.R index c9da077..cbb53d2 100644 --- a/R/add-rows.R +++ b/R/add-rows.R @@ -11,10 +11,11 @@ #' #' @param R latin rectangle #' @param rows empty rows to be filled +#' @param strategy row filling strategy #' -#' @return A latin rectangle with more rows. +#' @return #' @export -add_rows <- function(R, rows) { +add_rows <- function(R, rows, strategy = next_row_matching) { # we assume that the dimension equals # the number of columns @@ -22,16 +23,10 @@ add_rows <- function(R, rows) { for (i in rows) { - R <- R |> - dplyr::bind_rows( - tibble::tibble( - row = rep(i, l_order), - column = 1:l_order, - symbol = next_row(R, l_order) - ) - ) + R <- strategy(R, i, l_order) } return(R) + } \ No newline at end of file diff --git a/man/add_rows.Rd b/man/add_rows.Rd index 36c0675..6df4b35 100644 --- a/man/add_rows.Rd +++ b/man/add_rows.Rd @@ -4,15 +4,14 @@ \alias{add_rows} \title{Embed latin rectangle in a latin square} \usage{ -add_rows(R, rows) +add_rows(R, rows, strategy = next_row_matching) } \arguments{ \item{R}{latin rectangle} \item{rows}{empty rows to be filled} -} -\value{ -A latin rectangle with more rows. + +\item{strategy}{row filling strategy} } \description{ Input is a latin rectangle as a data frame with