diff --git a/NAMESPACE b/NAMESPACE index a0d86f4..bcfb9a5 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,15 +2,15 @@ export("%+%") export(export_answer) +export(fob_among) +export(fob_date) +export(fob_integer) +export(fob_numeric) +export(fob_text) +export(fob_word) export(join) export(match_pattern) export(multi) -export(one_among) -export(one_date) -export(one_integer) -export(one_numeric) -export(one_text) -export(one_word) importFrom(cli,style_bold) importFrom(cli,style_underline) importFrom(crayon,blue) diff --git a/R/join.R b/R/join.R index b7835a2..0d4c7eb 100644 --- a/R/join.R +++ b/R/join.R @@ -10,10 +10,10 @@ join <- function(...) { tmp <- list(...) n <- length(tmp) if (n == 1) { - out <- to_form(tmp[[1]]) + out <- to_form(tmp[[1L]]) } else { if (n > 1) { - out <- join_pair(tmp[[1]], tmp[[2]]) + out <- join_pair(tmp[[1L]], tmp[[2L]]) if (n > 2) { for (i in seq(3, n)) { out <- join_pair(out, tmp[[i]]) diff --git a/R/one_among.R b/R/one_among.R index 947ae7e..f1b2f55 100644 --- a/R/one_among.R +++ b/R/one_among.R @@ -9,7 +9,7 @@ #' @return Return the choice selected either as the choice value or its identifier (an integer). #' @export -one_among <- function(question, choices, field_name = "", output = "choice", +fob_among <- function(question, choices, field_name = "", output = "choice", ...) { output <- match.arg(output, c("choice", "id")) diff --git a/R/one_integer.R b/R/one_integer.R index 3d10f39..8562fdf 100644 --- a/R/one_integer.R +++ b/R/one_integer.R @@ -10,15 +10,15 @@ #' @return Return the choice selected either as the choice value or its identifier (an integer). #' @export -one_integer <- function(question, field_name = "", prompt = NULL) { +fob_integer <- function(question, field_name = "", prompt = NULL) { if (is.null(prompt)) prompt <- "Enter your answer (an integer): " generate_form_pattern(question = question, prompt = prompt, pattern = "^[0-9]+$", confirm = FALSE, pre = NULL, post = as.integer, field_name = field_name) } -#' @describeIn one_integer a numeric. +#' @describeIn fob_integer a numeric. #' @export -one_numeric <- function(question, field_name = "", prompt = NULL) { +fob_numeric <- function(question, field_name = "", prompt = NULL) { if (is.null(prompt)) prompt <- "Enter your answer (a numeric): " generate_form_pattern(question = question, prompt = prompt, pattern = "^[0-9]+\\.?[0-9]*$|^[0-9]*\\.?[0-9]+$", confirm = FALSE, @@ -26,9 +26,9 @@ one_numeric <- function(question, field_name = "", prompt = NULL) { } -#' @describeIn one_integer a word. +#' @describeIn fob_integer a word. #' @export -one_word <- function(question, field_name = "", prompt = NULL) { +fob_word <- function(question, field_name = "", prompt = NULL) { if (is.null(prompt)) prompt <- "Enter your answer (one word): " generate_form_pattern(question = question, prompt = prompt, pattern = "^[A-Za-z\\-]+$", pre = NULL, post = NULL, confirm = FALSE, @@ -36,9 +36,9 @@ one_word <- function(question, field_name = "", prompt = NULL) { } -#' @describeIn one_integer a text. +#' @describeIn fob_integer a text. #' @export -one_text <- function(question, field_name = "", max = NULL, prompt = NULL, ...) { +fob_text <- function(question, field_name = "", max = NULL, prompt = NULL, ...) { if (is.null(prompt)) { if (is.null(max)) { @@ -66,9 +66,9 @@ one_text <- function(question, field_name = "", max = NULL, prompt = NULL, ...) } -#' @describeIn one_integer a date. +#' @describeIn fob_integer a date. #' @export -one_date <- function(question, field_name = "", format = "%Y-%m-%d", +fob_date <- function(question, field_name = "", format = "%Y-%m-%d", prompt = NULL, ...) { if (is.null(prompt)) @@ -82,9 +82,9 @@ one_date <- function(question, field_name = "", format = "%Y-%m-%d", } -#' @describeIn one_integer `TRUE` for yes and `FALSE` for no. +#' @describeIn fob_integer `TRUE` for yes and `FALSE` for no. -one_yorn <- function(question, field_name = "", +fob_yorn <- function(question, field_name = "", prompt = "Enter [Y]es or [N]o: ", ...) { f_post <- function(x) grepl("^Y", x) @@ -102,9 +102,9 @@ one_yorn <- function(question, field_name = "", } -#' @describeIn one_integer one boolean/logical (i.e. `TRUE` or `FALSE`). +#' @describeIn fob_integer one boolean/logical (i.e. `TRUE` or `FALSE`). -one_boolean <- function(question, field_name = "", +fob_boolean <- function(question, field_name = "", prompt = "Enter [T]RUE or [F]ALSE: ", ...) { f_post <- function(x) grepl("^T", x) diff --git a/man/one_among.Rd b/man/fob_among.Rd similarity index 85% rename from man/one_among.Rd rename to man/fob_among.Rd index 3d356ed..ac858fb 100644 --- a/man/one_among.Rd +++ b/man/fob_among.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/one_among.R -\name{one_among} -\alias{one_among} +\name{fob_among} +\alias{fob_among} \title{A binary question to be answered by Yes or No.} \usage{ -one_among(question, choices, field_name = "", output = "choice", ...) +fob_among(question, choices, field_name = "", output = "choice", ...) } \arguments{ \item{question}{The question to be asked.} diff --git a/man/one_integer.Rd b/man/fob_integer.Rd similarity index 52% rename from man/one_integer.Rd rename to man/fob_integer.Rd index 59b8542..f6e44e9 100644 --- a/man/one_integer.Rd +++ b/man/fob_integer.Rd @@ -1,28 +1,28 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/one_integer.R -\name{one_integer} -\alias{one_integer} -\alias{one_numeric} -\alias{one_word} -\alias{one_text} -\alias{one_date} -\alias{one_yorn} -\alias{one_boolean} +\name{fob_integer} +\alias{fob_integer} +\alias{fob_numeric} +\alias{fob_word} +\alias{fob_text} +\alias{fob_date} +\alias{fob_yorn} +\alias{fob_boolean} \title{A binary question to be answered by Yes or No.} \usage{ -one_integer(question, field_name = "", prompt = NULL) +fob_integer(question, field_name = "", prompt = NULL) -one_numeric(question, field_name = "", prompt = NULL) +fob_numeric(question, field_name = "", prompt = NULL) -one_word(question, field_name = "", prompt = NULL) +fob_word(question, field_name = "", prompt = NULL) -one_text(question, field_name = "", max = NULL, prompt = NULL, ...) +fob_text(question, field_name = "", max = NULL, prompt = NULL, ...) -one_date(question, field_name = "", format = "\%Y-\%m-\%d", prompt = NULL, ...) +fob_date(question, field_name = "", format = "\%Y-\%m-\%d", prompt = NULL, ...) -one_yorn(question, field_name = "", prompt = "Enter [Y]es or [N]o: ", ...) +fob_yorn(question, field_name = "", prompt = "Enter [Y]es or [N]o: ", ...) -one_boolean( +fob_boolean( question, field_name = "", prompt = "Enter [T]RUE or [F]ALSE: ", @@ -50,16 +50,16 @@ A binary question to be answered by Yes or No. } \section{Functions}{ \itemize{ -\item \code{one_numeric}: a numeric. +\item \code{fob_numeric}: a numeric. -\item \code{one_word}: a word. +\item \code{fob_word}: a word. -\item \code{one_text}: a text. +\item \code{fob_text}: a text. -\item \code{one_date}: a date. +\item \code{fob_date}: a date. -\item \code{one_yorn}: \code{TRUE} for yes and \code{FALSE} for no. +\item \code{fob_yorn}: \code{TRUE} for yes and \code{FALSE} for no. -\item \code{one_boolean}: one boolean/logical (i.e. \code{TRUE} or \code{FALSE}). +\item \code{fob_boolean}: one boolean/logical (i.e. \code{TRUE} or \code{FALSE}). }} diff --git a/tests/testthat/test_basic.R b/tests/testthat/test_basic.R index a1c2097..434a02c 100644 --- a/tests/testthat/test_basic.R +++ b/tests/testthat/test_basic.R @@ -5,4 +5,4 @@ q2 <- one_yorn("Be or not to be", "shake") q3 <- one_date("When was that?", "date") q4 <- match_pattern("2 letters + 1 digit", "^[A-Za-z]{2}[0-9]$") myform <- q1 %+% q2 %+% q3 %+% q4 -# res <- myform() \ No newline at end of file +# res <- myform() \ No newline at end of file