Downloads the 20 Newsgroups dataset, which contains approximately 20,000 newsgroup documents from 20 different newsgroups. The distribution is approximately balanced.
Usage
download_twenty_newsgroups(
subset = "all",
verbose = FALSE,
tmpdir = NULL,
cleanup = TRUE,
timeout = 1800
)Format
A data frame with 6 variables:
Id: A stable source-derived identifier containing the subset, newsgroup, and original filename, e.g.train/alt.atheism/49960.FileId: The original source filename as a character value. These are not unique across subsets and newsgroups.Text: The full text of the message including any header, footer, and quotes. Newlines are preserved.Subset: A factor with two levels:trainandtest, indicating whether the document is from the training or test subset.Label: A factor with levels0through19, identifying the newsgroup using the canonical ordering below.Newsgroup: A factor with the 20 newsgroups as levels in the canonical ordering below.
The labels correspond to:
0: alt.atheism1: comp.graphics2: comp.os.ms-windows.misc3: comp.sys.ibm.pc.hardware4: comp.sys.mac.hardware5: comp.windows.x6: misc.forsale7: rec.autos8: rec.motorcycles9: rec.sport.baseball10: rec.sport.hockey11: sci.crypt12: sci.electronics13: sci.med14: sci.space15: soc.religion.christian16: talk.politics.guns17: talk.politics.mideast18: talk.politics.misc19: talk.religion.misc
Newsgroup contains the corresponding names.
There are 11,314 items in the train dataset and 7,532 items in the
test for a total of 18,846 items if you choose subset = "all".
Arguments
- subset
A string specifying which subset of the dataset to download and process. Acceptable values are
"train"for the training set,"test"for the test set, and"all"for both sets combined. Default is"all".- verbose
If
TRUE, log progress of download, extraction and processing.- tmpdir
A string specifying the parent directory for a dedicated download and extraction work directory. If
NULL(default), a temporary parent directory is used. If a path is provided and does not exist, it will be created.- cleanup
A logical flag indicating whether to delete the downloaded and extracted files after processing. If
TRUEandtmpdirwas created by this function,tmpdirwill be deleted after processing. Default isTRUE.- timeout
Minimum download timeout in seconds. The default is 30 minutes; a larger existing global R timeout is preserved.
Details
To do any analysis on this text, you will want to use tools from packages
such as tm and
tidytext. The files
are read as latin1 encoding, but there can still be some odd control
codes in some of the messages.
References
Lang, K. (1995). Newsweeder: Learning to filter netnews. In Proceedings of the Twelfth International Conference on Machine Learning 1995 (pp. 331-339). Morgan Kaufmann.
See also
http://qwone.com/~jason/20Newsgroups/
Chapter 9 of Tidy Text Mining with R for a case study using the same dataset.
Examples
if (FALSE) { # \dontrun{
# Download and process the training set
ng_train <- download_twenty_newsgroups(subset = "train")
# Download and process both training and test sets, with verbose output
ng_all <- download_twenty_newsgroups(subset = "all", verbose = TRUE)
# Download and process the test set, using a specific directory and enabling
# cleanup
ng_test <- download_twenty_newsgroups(
subset = "test",
tmpdir = "path/to/dir", cleanup = TRUE
)
} # }