Skip to content

Commit

Permalink
Added default encoding and changed to readLines instead stringi
Browse files Browse the repository at this point in the history
  • Loading branch information
JBGruber committed Dec 18, 2019
1 parent 16c64ed commit 583c009
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
13 changes: 8 additions & 5 deletions R/rwhatsapp.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#' \link[stringi]{stri_datetime_parse} for guidance.
#' @param verbose A logical flag indicating whether information should be
#' printed to the screen.
#' @param ... Further arguments passed to \link[stringi]{stri_read_lines}.
#' @param encoding Input encoding. Should usually be "UTF-8" if files haven't
#' changed since export from WhatsApp.
#' @param ... Further arguments passed to \link[base]{readLines}.
#'
#' @return A tibble with the information parsed from the history file.
#' @export
Expand All @@ -31,6 +33,7 @@ rwa_read <- function(x,
tz = NULL,
format = NULL,
verbose = FALSE,
encoding = "UTF-8",
...) {

if (verbose) {
Expand All @@ -40,7 +43,7 @@ rwa_read <- function(x,
start_time <- NULL
}

chat_raw <- rwa_read_lines(x, verbose, start_time, ...)
chat_raw <- rwa_read_lines(x, verbose, start_time, encoding, ...)

chat_raw <- chat_raw[!chat_raw == ""]
time <- stri_extract_first_regex(
Expand Down Expand Up @@ -126,7 +129,7 @@ rwa_read <- function(x,
#' @inherit rwa_read
#' @import stringi
#' @noRd
rwa_read_lines <- function(x, verbose, start_time = NULL, ...) {
rwa_read_lines <- function(x, verbose, start_time = NULL, encoding, ...) {
# get files
zps <- grep(".zip$", x, ignore.case = TRUE)
temp <- NULL
Expand All @@ -144,15 +147,15 @@ rwa_read_lines <- function(x, verbose, start_time = NULL, ...) {

if (f_exist_s(x)) {
if (length(x) == 1) {
chat_raw <- stri_read_lines(x, ...)
chat_raw <- readLines(x, encoding = encoding, ...)
names(chat_raw) <- rep(x, length(chat_raw))
if (verbose) {
message(" one log file...")
status("one log file loaded")
}
} else {
chat_raw <- unlist(lapply(x, function(t) {
cr <- stri_read_lines(t)#, ...)
cr <- readLines(t, encoding = encoding, ...)
names(cr) <- rep(t, length(cr))
return(cr)
}))
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.re
![Downloads](https://cranlogs.r-pkg.org/badges/grand-total/rwhatsapp)
[![Travis-CI Build
Status](https://travis-ci.org/JBGruber/rwhatsapp.svg?branch=master)](https://travis-ci.org/JBGruber/rwhatsapp)
[![Say


## Motivation

Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Macbook
ne
oman
prozessor
readLines
stopwords
stri
tf
Expand Down
7 changes: 5 additions & 2 deletions man/rwa_read.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 583c009

Please sign in to comment.