rio (version 0.5.30)

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)))

Value

A logical

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))

Examples

Run this code
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)

Run the code above in your browser using DataLab