Learn R Programming

fdm2id (version 1.0.1)

loadtext: load a text file

Description

(Down)Load a text file (and extract it if it is in a zip file).

Usage

loadtext(
  file = NULL,
  dir = tempdir(),
  collapse = TRUE,
  sep = NULL,
  categories = NULL,
  cache = FALSE
)

Value

The text contained in the dowloaded file.

Arguments

file

The path or URL of the text file. If not specified, defaults to an interactive file chooser (file.choose) when running interactively; in a non-interactive session (script, CI, R CMD check), file must be given explicitly.

dir

The directory the file is downloaded (and, for a zip archive, extracted) into. Defaults to the session's temporary directory, which is emptied when R exits. Pass an explicit path (together with cache = TRUE) to keep the downloaded corpus between sessions.

collapse

Indicates whether or not lines of each documents should collapse together or not.

sep

Separator between text fields.

categories

Columns that should be considered as categorical data.

cache

Whether the downloaded (and, for a zip archive, extracted) files are kept in dir and reused on the next call. They are deleted, and downloaded again every time, by default.

See Also

Examples

Run this code
# Not run automatically: this downloads a 31 MB archive from a third-party server, so it
# depends on both the network and that server staying up.
if (FALSE) {
text = loadtext ("http://mattmahoney.net/dc/text8.zip")
# Keep the archive between calls, in a directory of your choosing
text = loadtext ("http://mattmahoney.net/dc/text8.zip", dir = "~/corpora", cache = TRUE)
}

Run the code above in your browser using DataLab