load_text_content: Load the content of a text file.

View source: R/fcts.R

load_text_contentR Documentation

Load the content of a text file.

Description

Load the content of a text file, trying to guess file encoding. The content is returned as a single character value.

Usage

load_text_content(path, min.confidence = 0)

Arguments

path

Path to the file from which to load content.

min.confidence

The minimum confidence value (between 0 and 1)

Value

The content of the file as a single character value, NA_character_ if encoding was not recognized.

Examples

# Create a file in Latin-1 encoding
text_file <- tempfile('myfile', fileext = '.txt')
dir.create(dirname(text_file), recursive = TRUE)
x <- iconv("Qui sème le vent récolte la tempête.",
           from = "utf8", to = "latin1")
stringi::stri_write_lines(x, text_file, encoding = "latin1")

# Load its content
content <- fscache::load_text_content(text_file)
content

# Remove file
unlink(text_file)


fscache documentation built on June 22, 2024, 10:36 a.m.