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

[Request] add text= argument to fread, to read from multi-line character vectors #1423

Closed
clarkdk opened this issue Nov 5, 2015 · 0 comments

Comments

@clarkdk
Copy link

clarkdk commented Nov 5, 2015

fread() cannot read from a multi-line text object, but it can read a length 1 character vector. Multi-line vectors are typically created using readLines(). My feature request is to support input from multi-line character vectors, as read.table() does.

read.table() accepts character vector input in two ways:

  1. as a text connection on the file= argument -- read.table(file=textConnection(textvar,...),...), or
  2. using the text= argument, which wraps the input with a textConnection().
    In both cases, the character vector can be of any length, and is read as text lines.

A work-around for fread is to collapse the character vector to length 1, using paste0() or stri_flatten(), as in

  paste0(textvar, collapse = "\n")
  stri_flatten(textvar, collapse = "\n")

and use the result as input to the fread's input= argument. Unless a faster way is immediately obvious, the text= argument could be initially implemented using one of these collapse functions. This would be quite convenient when text files need pre-processing before reading with fread..

When connections are implemented in fread (#561) then the text= argument could be implemented as a textConnection, as read.table(text=...) now does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants