loadtext: load a text file

loadtextR Documentation

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
)

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.

Value

The text contained in the dowloaded file.

See Also

download.file, unzip

Examples

# 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.
## Not run: 
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)

## End(Not run)

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.