Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add sep parameter to readtext #171

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ Encoding: UTF-8
BugReports: https://github.com/quanteda/readtext/issues
LazyData: TRUE
VignetteBuilder: knitr
RoxygenNote: 7.1.1
RoxygenNote: 7.2.1
Roxygen: list(markdown = TRUE)
9 changes: 5 additions & 4 deletions R/readtext.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#' \item 2: output a brief summary message
#' \item 3: output detailed file-related messages
#' }
#' @param sep separator for csv, default to ","
#' @param ... additional arguments passed through to low-level file reading
#' function, such as [file()], [fread()], etc. Useful
#' for specifying an input encoding option, which is specified in the same was
Expand Down Expand Up @@ -156,7 +157,7 @@ readtext <- function(file, ignore_missing_files = FALSE, text_field = NULL,
docid_field = NULL,
docvarsfrom = c("metadata", "filenames", "filepaths"), dvsep = "_",
docvarnames = NULL, encoding = NULL, source = NULL, cache = TRUE,
verbosity = readtext_options("verbosity"),
sep = ",", verbosity = readtext_options("verbosity"),
...) {

args <- list(...)
Expand Down Expand Up @@ -205,7 +206,7 @@ readtext <- function(file, ignore_missing_files = FALSE, text_field = NULL,

sources <- mapply(function(x, e) {
get_source(x, text_field = text_field, docid_field = docid_field,
encoding = e, source = source, verbosity = verbosity, ...)
encoding = e, source = source, verbosity = verbosity, sep = sep, ...)
}, files, encoding, SIMPLIFY = FALSE)

# combine all of the data.frames returned
Expand Down Expand Up @@ -241,7 +242,7 @@ readtext <- function(file, ignore_missing_files = FALSE, text_field = NULL,

## Read each file as appropriate, calling the get_* functions for recognized
## file types
get_source <- function(path, text_field, docid_field, replace_specialchar = FALSE, verbosity = 1, ...,
get_source <- function(path, text_field, docid_field, replace_specialchar = FALSE, verbosity = 1, sep, ...,
# deprecated arguments
textfield) {

Expand All @@ -264,7 +265,7 @@ get_source <- function(path, text_field, docid_field, replace_specialchar = FALS

result <- switch(ext,
txt = get_txt(path, ...),
csv = get_csv(path, text_field, docid_field, sep = ",", ...),
csv = get_csv(path, text_field, docid_field, sep = sep, ...),
tsv = get_csv(path, text_field, docid_field, sep = "\t", ...),
tab = get_csv(path, text_field, docid_field, sep = "\t", ...),
json = get_json(path, text_field, docid_field, verbosity = verbosity, ...),
Expand Down
3 changes: 3 additions & 0 deletions man/readtext.Rd

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