Skip to content

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

@clarkdk

Description

@clarkdk

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions