% Generated by roxygen2: do not edit by hand % Please edit documentation in R/io.R \name{read_utf8} \alias{read_utf8} \alias{write_utf8} \alias{append_utf8} \alias{append_unique} \title{Read / write files encoded in UTF-8} \usage{ read_utf8(con, error = FALSE, binary = FALSE) write_utf8(text, con, ...) append_utf8(text, con, sort = TRUE) append_unique(text, con, sort = function(x) base::sort(unique(x))) } \arguments{ \item{con}{A connection or a file path.} \item{error}{Whether to signal an error when non-UTF8 characters are detected (if \code{FALSE}, only a warning message is issued).} \item{binary}{Whether to read the file via a binary-mode connection. On Windows, \code{\link[=readLines]{readLines()}} on a text-mode connection (the default) treats a \code{Ctrl+Z} byte (\verb{\\x1a}) as end-of-file and silently truncates the file (e.g., self-contained HTML embedding the PNG signature \verb{\\x89PNG\\r\\n\\x1a\\n} in JavaScript). Set \code{binary = TRUE} to read the whole file regardless of \code{Ctrl+Z} bytes (this has a small overhead and is only necessary on Windows). This argument is only used when \code{con} is a file path.} \item{text}{A character vector (will be converted to UTF-8 via \code{\link[=enc2utf8]{enc2utf8()}}).} \item{...}{Other arguments passed to \code{\link[=writeLines]{writeLines()}} (except \code{useBytes}, which is \code{TRUE} in \code{write_utf8()}).} \item{sort}{Logical (\code{FALSE} means not to sort the content) or a function to sort the content; \code{TRUE} is equivalent to \code{base::sort}.} } \value{ \code{read_utf8()} returns a character vector of the file content; \code{write_utf8()} returns the \code{con} argument (invisibly). } \description{ Read or write files, assuming they are encoded in UTF-8. \code{read_utf8()} is roughly \code{readLines(encoding = 'UTF-8')} (a warning will be issued if non-UTF8 lines are found), and \code{write_utf8()} calls \code{writeLines(enc2utf8(text), useBytes = TRUE)}. } \details{ The function \code{append_utf8()} appends UTF-8 content to a file or connection based on \code{read_utf8()} and \code{write_utf8()}, and optionally sort the content. The function \code{append_unique()} appends unique lines to a file or connection. }