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)))
Path to the file
Maximum number of bytes to read
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))
as.raw(c(7:16, 18, 19, 32:127))
A logical
# NOT RUN { 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") # }
Run the code above in your browser using DataLab