Skip to content

Commit

Permalink
Bind mbox_df class
Browse files Browse the repository at this point in the history
  • Loading branch information
JooYoung Seo committed Nov 3, 2020
1 parent 9cd295c commit 6b03093
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions R/globals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
utils::globalVariables(c("num_discussants", "subject"))
1 change: 1 addition & 0 deletions R/merge_mbox_all.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ merge_mbox_all <-
}
}

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
8 changes: 6 additions & 2 deletions R/preprocessing.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
#' @export

# Remove carriage return and trim white spaces in subject line
trim_subject <- function(df) {
df %>%
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.")
}

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 = " "))
}
Expand Down
1 change: 1 addition & 0 deletions R/read_mbox.R
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,6 @@ read_mbox <-
warning("Something is wrong with your output file name. Currently only 'RDS' format is supported.")
}
}
class(df) <- c("mbox_df", class(df))
return(df)
} # Function ends.
9 changes: 8 additions & 1 deletion R/thread.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#' @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.")
}

mbox_df %>%
is_thread() %>%
sum(., na.rm = TRUE)
Expand All @@ -40,6 +44,9 @@ sum(., na.rm = TRUE)
#' @export

is_thread <- function(mbox_df) {
# checkMbox_df(mbox_df)["num_discussants"] > 1
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 6b03093

Please sign in to comment.