Skip to content

Commit

Permalink
Merge pull request #126 from quanteda/issue-123
Browse files Browse the repository at this point in the history
Issue 123
  • Loading branch information
kbenoit committed May 6, 2018
2 parents d9a19b5 + 829be8b commit 5dc1df7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
40 changes: 38 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,42 @@
.Rproj.user
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
/*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# Shiny token, see https://shiny.rstudio.com/articles/shinyapps.html
rsconnect/

.Ruserdata
readtext.Rproj
*.Rproj

*.DS_Store

3 changes: 2 additions & 1 deletion R/encoding.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ encoding <- function(x, verbose = TRUE, ...) {
#' @export
#' @import data.table stringi
encoding.character <- function(x, verbose = TRUE, ...) {
verbosity <- ifelse(is.null(getOption("readtext_verbosity")), 1, getOption("readtext_verbosity"))

addedArgs <- names(list(...))
if (length(addedArgs) && any(!(addedArgs %in% names(formals(stringi::stri_enc_detect)))))
if (getOption("readtext_verbosity") >= 1)
if (verbosity >= 1)
warning("Argument", ifelse(length(addedArgs) > 1, "s ", " "), addedArgs, " not used.", sep = "", noBreaks. = TRUE)

encoding <- confidence <- conf <- NULL
Expand Down
3 changes: 2 additions & 1 deletion R/readtext.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ readtext <- function(file, ignore_missing_files = FALSE, text_field = NULL,
warning("textfield is deprecated; use text_field instead.")
text_field <- args[["textfield"]]
}


# in case the function was called without attaching the package,
# in which case the option is never set
Expand All @@ -182,7 +183,7 @@ readtext <- function(file, ignore_missing_files = FALSE, text_field = NULL,
source <- "auto"
if (verbosity >= 2)
message("Reading texts from ", file)

files <- list_files(file, ignore_missing_files, FALSE, verbosity)
if (length(encoding) == 1) {
encoding <- rep(encoding, length(files))
Expand Down
7 changes: 3 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ downloadRemote <- function (i, ignore_missing) {
# by looking at the extension, because '/path/to/*.zip' is a glob expression
# with a 'zip' extension.
list_files <- function(x, ignore_missing = FALSE, last_round = FALSE, verbosity = 1) {

if (!(ignore_missing || (length(x) > 0)))
stop("File '", x, "' does not exist.")

Expand Down Expand Up @@ -159,7 +158,7 @@ list_file <- function(x, ignore_missing, last_round, verbosity) {
# Remove "file" scheme
i <- stri_replace_first_regex(x, "^file://", "")
scheme <- stri_match_first_regex(i, "^([A-Za-z][A-Za-z0-9+.-]+)://")[, 2]

# If not a URL (or a file:// URL) , treat it as a local file
if (!is.na(scheme)) {
if (verbosity >= 3)
Expand Down Expand Up @@ -191,12 +190,12 @@ list_file <- function(x, ignore_missing, last_round, verbosity) {
if (!(ignore_missing || file.exists(i)))
stop("File '", i, "' does not exist.")

if (getOption("readtext_verbosity") >= 3)
if (verbosity >= 3)
message("... reading (", tools::file_ext(i), ") file: ", basename(i))
return(i)
} else {
# If it wasn't a glob pattern last time, then it may be this time
if (getOption("readtext_verbosity") >= 3) message(", using glob pattern")
if (verbosity >= 3) message(", using glob pattern")
i <- Sys.glob(i)
return(
list_files(i, ignore_missing, TRUE, verbosity)
Expand Down

0 comments on commit 5dc1df7

Please sign in to comment.