| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/io.R |
| 3 |
\name{read_utf8} |
| 4 |
\alias{read_utf8} |
| 5 |
\alias{write_utf8} |
| 6 |
\alias{append_utf8} |
| 7 |
\alias{append_unique} |
| 8 |
\title{Read / write files encoded in UTF-8} |
| 9 |
\usage{ |
| 10 |
read_utf8(con, error = FALSE, binary = FALSE) |
| 11 |
|
| 12 |
write_utf8(text, con, ...) |
| 13 |
|
| 14 |
append_utf8(text, con, sort = TRUE) |
| 15 |
|
| 16 |
append_unique(text, con, sort = function(x) base::sort(unique(x))) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{con}{A connection or a file path.} |
| 20 |
|
| 21 |
\item{error}{Whether to signal an error when non-UTF8 characters are detected |
| 22 |
(if \code{FALSE}, only a warning message is issued).} |
| 23 |
|
| 24 |
\item{binary}{Whether to read the file via a binary-mode connection. On |
| 25 |
Windows, \code{\link[=readLines]{readLines()}} on a text-mode connection (the default) treats a |
| 26 |
\code{Ctrl+Z} byte (\verb{\\x1a}) as end-of-file and silently truncates the file |
| 27 |
(e.g., self-contained HTML embedding the PNG signature |
| 28 |
\verb{\\x89PNG\\r\\n\\x1a\\n} in JavaScript). Set \code{binary = TRUE} to read the whole |
| 29 |
file regardless of \code{Ctrl+Z} bytes (this has a small overhead and is only |
| 30 |
necessary on Windows). This argument is only used when \code{con} is a file |
| 31 |
path.} |
| 32 |
|
| 33 |
\item{text}{A character vector (will be converted to UTF-8 via \code{\link[=enc2utf8]{enc2utf8()}}).} |
| 34 |
|
| 35 |
\item{...}{Other arguments passed to \code{\link[=writeLines]{writeLines()}} (except \code{useBytes}, which |
| 36 |
is \code{TRUE} in \code{write_utf8()}).} |
| 37 |
|
| 38 |
\item{sort}{Logical (\code{FALSE} means not to sort the content) or a |
| 39 |
function to sort the content; \code{TRUE} is equivalent to |
| 40 |
\code{base::sort}.} |
| 41 |
} |
| 42 |
\value{ |
| 43 |
\code{read_utf8()} returns a character vector of the file content; |
| 44 |
\code{write_utf8()} returns the \code{con} argument (invisibly). |
| 45 |
} |
| 46 |
\description{ |
| 47 |
Read or write files, assuming they are encoded in UTF-8. \code{read_utf8()} is |
| 48 |
roughly \code{readLines(encoding = 'UTF-8')} (a warning will be issued if non-UTF8 |
| 49 |
lines are found), and \code{write_utf8()} calls \code{writeLines(enc2utf8(text), useBytes = TRUE)}. |
| 50 |
} |
| 51 |
\details{ |
| 52 |
The function \code{append_utf8()} appends UTF-8 content to a file or connection |
| 53 |
based on \code{read_utf8()} and \code{write_utf8()}, and optionally sort the content. |
| 54 |
The function \code{append_unique()} appends unique lines to a file or connection. |
| 55 |
} |