From c80ec6259ed6c47d3187d3c2c23eda08b26bdaf0 Mon Sep 17 00:00:00 2001 From: flavis Date: Tue, 10 Aug 2021 14:39:35 +0200 Subject: [PATCH] add additional parameter checks for analyze methods --- R/analyze.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/analyze.R b/R/analyze.R index 7f32244..29d3399 100644 --- a/R/analyze.R +++ b/R/analyze.R @@ -8,6 +8,7 @@ #' @export find_word <- function(res, word) { is_valid_res(res) + stopifnot("word must be of type character" = is.character(word)) talks <- res$talks mutate( talks, @@ -25,11 +26,15 @@ find_word <- function(res, word) { #' @param fraction_only if TRUE, only select fraction from the resulting joined tibble #' #' left join speaker information from res$speaker into tb. -#' if fraction_only +#' if fraction_only, drop all columns but fraction #' #' @export join_speaker <- function(tb, res, fraction_only = F) { is_valid_res(res) + stopifnot("fraction_only must be of type logical" = is.logical(fraction_only)) + stopifnot("tb must be a tibble" = inherits(tb, "tbl")) + stopifnot("tb must have a speaker column" = "speaker" %in% names(tb)) + joined <- left_join(tb, res$speaker, by=c("speaker" = "id")) if (fraction_only) select(joined, "fraction") else joined @@ -160,6 +165,9 @@ bar_plot_fractions <- function(tb, #' @export word_usage_by_date <- function(res, patterns, tidy=F) { is_valid_res(res) + stopifnot("patterns must be of type character" = is.character(patterns)) + stopifnot("tidy must be of type logical" = is.logical(tidy)) + tb <- res$talks nms <- names(patterns) for (i in seq_along(patterns)) {