is_file_text {rio} | R Documentation |
Determine whether a file is “plain-text” or some sort of binary format
is_file_text(file, maxsize = Inf, text_bytes = as.raw(c(7:16, 18, 19, 32:255)))
file |
Path to the file |
maxsize |
Maximum number of bytes to read |
text_bytes |
Which characters are used by normal text (though not
necessarily just ASCII). To detect just ASCII, the
following value can be used:
|
A logical
library(datasets) export(iris, yml_file <- tempfile(fileext = ".yml")) is_file_text(yml_file) # TRUE export(iris, sav_file <- tempfile(fileext = ".sav")) is_file_text(sav_file) # FALSE # cleanup unlink(yml_file) unlink(sav_file)