From 314b9d71bdfddece772278902a8d52232f61c952 Mon Sep 17 00:00:00 2001 From: JooYoung Seo Date: Sun, 27 Dec 2020 13:35:13 -0500 Subject: [PATCH] Use tidyverse style --- R/merge_mbox_all.R | 16 ++++++++-------- R/preprocessing.R | 13 ++++++------- R/thread.R | 16 ++++++++-------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/R/merge_mbox_all.R b/R/merge_mbox_all.R index 95e91d8..cec88d3 100644 --- a/R/merge_mbox_all.R +++ b/R/merge_mbox_all.R @@ -38,17 +38,17 @@ merge_mbox_all <- function(path = ".", file = NULL) { # Function starts: if (length(list.files(path, pattern = "(*.mbox)$")) > 0) { -# if (path != ".") { -# current_wd <- getwd() -# setwd(path) -# } + # if (path != ".") { + # current_wd <- getwd() + # setwd(path) + # } multi_mbox <- list.files(path, pattern = "(*.mbox)$") %>% purrr::map_df(~ mboxr::read_mbox(.)) -# if (path != ".") { -# setwd(current_wd) -# } + # if (path != ".") { + # setwd(current_wd) + # } if (!is.null(file)) { fileExt <- tolower(tools::file_ext(file)) @@ -61,7 +61,7 @@ merge_mbox_all <- } } -class(multi_mbox) <- c("mbox_df", class(multi_mbox)) + class(multi_mbox) <- c("mbox_df", class(multi_mbox)) return(multi_mbox) } else { stop("No mbox file is found in the current directory.") diff --git a/R/preprocessing.R b/R/preprocessing.R index 43e6a44..fe9b904 100644 --- a/R/preprocessing.R +++ b/R/preprocessing.R @@ -3,12 +3,11 @@ # Remove carriage return and trim white spaces in subject line trim_subject <- function(mbox_df) { -if(!inherits(mbox_df, "mbox_df")) { -stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") -} + if (!inherits(mbox_df, "mbox_df")) { + stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") + } -mbox_df %>% -dplyr::mutate(subject = stringr::str_replace_all(string = subject, pattern = "[[:cntrl:]]+", replacement = " ")) %>% -dplyr::mutate(subject = stringr::str_replace_all(string = subject, pattern = "[[:space:]]+", replacement = " ")) + mbox_df %>% + dplyr::mutate(subject = stringr::str_replace_all(string = subject, pattern = "[[:cntrl:]]+", replacement = " ")) %>% + dplyr::mutate(subject = stringr::str_replace_all(string = subject, pattern = "[[:space:]]+", replacement = " ")) } - diff --git a/R/thread.R b/R/thread.R index f27fa23..628bd79 100644 --- a/R/thread.R +++ b/R/thread.R @@ -30,13 +30,13 @@ #' @author Soyoung Choi, \email{sxc940@psu.edu} num_thread <- function(mbox_df) { -if(!inherits(mbox_df, "mbox_df")) { -stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") -} + if (!inherits(mbox_df, "mbox_df")) { + stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") + } mbox_df %>% -is_thread() %>% -sum(., na.rm = TRUE) + is_thread() %>% + sum(., na.rm = TRUE) } @@ -44,9 +44,9 @@ sum(., na.rm = TRUE) #' @export is_thread <- function(mbox_df) { -if(!inherits(mbox_df, "mbox_df")) { -stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") -} + if (!inherits(mbox_df, "mbox_df")) { + stop("You need an mbox_df object for this function: Convert your mbox file through `read_mbox()` first.") + } mbox_df$num_discussants > 1 }