Skip to content

Commit

Permalink
Use tidyverse style
Browse files Browse the repository at this point in the history
  • Loading branch information
JooYoung Seo committed Dec 27, 2020
1 parent 6b03093 commit 314b9d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
16 changes: 8 additions & 8 deletions R/merge_mbox_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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.")
Expand Down
13 changes: 6 additions & 7 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = " "))
}

16 changes: 8 additions & 8 deletions R/thread.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
#' @author Soyoung Choi, \email{[email protected]}

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)
}


#' @rdname num_thread
#' @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
}

0 comments on commit 314b9d7

Please sign in to comment.