
Classify a downloaded .txt file from its content
Source:R/data_check_helpers.R
txt_classify_content.RdA .txt extension says nothing about what a file holds: research repositories
ship experiment data (E-Prime exports, Ibex/task logs), codebooks, and plain
prose notes all as .txt. The name-based classifier
(data_classify_files()) runs on remote file names before download, so it
cannot tell these apart and settles on a conservative guess. Once the file is
on disk, its content can. This is the same fetch-then-reclassify pattern the
module already uses for zips.
Details
Returns the data_check type the content implies:
"data"for an E-Prime export (its fixed*** Header Start ***/LevelName:header), or for a delimited table with a real header row;NA_character_when the content is not recognised, meaning "keep whatever the name-based classifier decided" – never a downgrade on a guess.
The file is only read, never modified or removed: the download cache is
persistent by design (see repo_cache_dir()), so classification decides how a
file is used, not whether it survives.
Examples
txt <- tempfile(fileext = ".txt")
writeLines(c("id rt condition", "1 512 congruent", "2 640 incongruent",
"3 498 congruent"), txt)
txt_classify_content(txt)
#> [1] "data"