-
Notifications
You must be signed in to change notification settings - Fork 285
/
Copy pathread_file.Rd
69 lines (57 loc) · 2.43 KB
/
read_file.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/file.R
\name{read_file}
\alias{read_file}
\alias{read_file_raw}
\alias{write_file}
\title{Read/write a complete file}
\usage{
read_file(file, locale = default_locale())
read_file_raw(file)
write_file(x, file, append = FALSE, path = deprecated())
}
\arguments{
\item{file}{Either a path to a file, a connection, or literal data
(either a single string or a raw vector).
Files ending in \code{.gz}, \code{.bz2}, \code{.xz}, or \code{.zip} will
be automatically uncompressed. Files starting with \verb{http://},
\verb{https://}, \verb{ftp://}, or \verb{ftps://} will be automatically
downloaded. Remote gz files can also be automatically downloaded and
decompressed.
Literal data is most useful for examples and tests. To be recognised as
literal data, the input must be either wrapped with \code{I()}, be a string
containing at least one new line, or be a vector containing at least one
string with a new line.
Using a value of \code{\link[=clipboard]{clipboard()}} will read from the system clipboard.}
\item{locale}{The locale controls defaults that vary from place to place.
The default locale is US-centric (like R), but you can use
\code{\link[=locale]{locale()}} to create your own locale that controls things like
the default time zone, encoding, decimal mark, big mark, and day/month
names.}
\item{x}{A single string, or a raw vector to write to disk.}
\item{append}{If \code{FALSE}, will overwrite existing file. If \code{TRUE},
will append to existing file. In both cases, if the file does not exist a new
file is created.}
\item{path}{\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} Use the \code{file} argument
instead.}
}
\value{
\code{read_file}: A length 1 character vector.
\code{read_lines_raw}: A raw vector.
}
\description{
\code{read_file()} reads a complete file into a single object: either a
character vector of length one, or a raw vector. \code{write_file()} takes a
single string, or a raw vector, and writes it exactly as is. Raw vectors
are useful when dealing with binary data, or if you have text data with
unknown encoding.
}
\examples{
read_file(file.path(R.home("doc"), "AUTHORS"))
read_file_raw(file.path(R.home("doc"), "AUTHORS"))
tmp <- tempfile()
x <- format_csv(mtcars[1:6, ])
write_file(x, tmp)
identical(x, read_file(tmp))
read_lines(I(x))
}