Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

is_file_text

Determine whether a file is “plain-text” or some sort of binary format


Description

Determine whether a file is “plain-text” or some sort of binary format

Usage

is_file_text(file, maxsize = Inf, text_bytes = as.raw(c(7:16, 18, 19, 32:255)))

Arguments

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: as.raw(c(7:16, 18, 19, 32:127))

Value

A logical

Examples

library(datasets)
export(iris, "iris.yml")
is_file_text("iris.yml") # TRUE

export(iris, "iris.sav")
is_file_text("iris.sav") # FALSE

# cleanup
unlink("iris.yml")
unlink("iris.sav")

rio

A Swiss-Army Knife for Data I/O

v0.5.26
GPL-2
Authors
Jason Becker [ctb], Chung-hong Chan [aut], Geoffrey CH Chan [ctb], Thomas J. Leeper [aut, cre] (<https://orcid.org/0000-0003-4097-6326>), Christopher Gandrud [ctb], Andrew MacDonald [ctb], Ista Zahn [ctb], Stanislaus Stadlmann [ctb], Ruaridh Williamson [ctb], Patrick Kennedy [ctb], Ryan Price [ctb], Trevor L Davis [ctb], Nathan Day [ctb], Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>), Alex Bokov [ctb] (<https://orcid.org/0000-0002-0511-9815>)
Initial release
2021-02-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.