Kaynağa Gözat

add additional parameter checks for analyze methods

genderequality-alternative
flavis 4 yıl önce
ebeveyn
işleme
c80ec6259e
1 değiştirilmiş dosya ile 9 ekleme ve 1 silme
  1. +9
    -1
      R/analyze.R

+ 9
- 1
R/analyze.R Dosyayı Görüntüle

@@ -8,6 +8,7 @@
#' @export #' @export
find_word <- function(res, word) { find_word <- function(res, word) {
is_valid_res(res) is_valid_res(res)
stopifnot("word must be of type character" = is.character(word))
talks <- res$talks talks <- res$talks
mutate( mutate(
talks, talks,
@@ -25,11 +26,15 @@ find_word <- function(res, word) {
#' @param fraction_only if TRUE, only select fraction from the resulting joined tibble #' @param fraction_only if TRUE, only select fraction from the resulting joined tibble
#' #'
#' left join speaker information from res$speaker into tb. #' left join speaker information from res$speaker into tb.
#' if fraction_only
#' if fraction_only, drop all columns but fraction
#' #'
#' @export #' @export
join_speaker <- function(tb, res, fraction_only = F) { join_speaker <- function(tb, res, fraction_only = F) {
is_valid_res(res) 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")) joined <- left_join(tb, res$speaker, by=c("speaker" = "id"))
if (fraction_only) select(joined, "fraction") if (fraction_only) select(joined, "fraction")
else joined else joined
@@ -160,6 +165,9 @@ bar_plot_fractions <- function(tb,
#' @export #' @export
word_usage_by_date <- function(res, patterns, tidy=F) { word_usage_by_date <- function(res, patterns, tidy=F) {
is_valid_res(res) 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 tb <- res$talks
nms <- names(patterns) nms <- names(patterns)
for (i in seq_along(patterns)) { for (i in seq_along(patterns)) {


Yükleniyor…
İptal
Kaydet