read_lines | R Documentation |
read_lines()
reads up to n_max
lines from a file. New lines are
not included in the output. read_lines_raw()
produces a list of raw
vectors, and is useful for handling data with unknown encoding.
write_lines()
takes a character vector or list of raw vectors, appending a
new line after each entry.
read_lines(
file,
skip = 0,
skip_empty_rows = FALSE,
n_max = Inf,
locale = default_locale(),
na = character(),
lazy = should_read_lazy(),
num_threads = readr_threads(),
progress = show_progress()
)
read_lines_raw(
file,
skip = 0,
n_max = -1L,
num_threads = readr_threads(),
progress = show_progress()
)
write_lines(
x,
file,
sep = "\n",
na = "NA",
append = FALSE,
num_threads = readr_threads(),
path = deprecated()
)
file |
Either a path to a file, a connection, or literal data (either a single string or a raw vector). Files ending in Literal data is most useful for examples and tests. To be recognised as
literal data, the input must be either wrapped with Using a value of |
skip |
Number of lines to skip before reading data. |
skip_empty_rows |
Should blank rows be ignored altogether? i.e. If this
option is |
n_max |
Number of lines to read. If |
locale |
The locale controls defaults that vary from place to place.
The default locale is US-centric (like R), but you can use
|
na |
Character vector of strings to interpret as missing values. Set this
option to |
lazy |
Read values lazily? By default, this is Learn more in |
num_threads |
The number of processing threads to use for initial
parsing and lazy reading of data. If your data contains newlines within
fields the parser should automatically detect this and fall back to using
one thread only. However if you know your file has newlines within quoted
fields it is safest to set |
progress |
Display a progress bar? By default it will only display
in an interactive session and not while knitting a document. The automatic
progress bar can be disabled by setting option |
x |
A character vector or list of raw vectors to write to disk. |
sep |
The line separator. Defaults to |
append |
If |
path |
read_lines()
: A character vector with one element for each line.
read_lines_raw()
: A list containing a raw vector for each line.
write_lines()
returns x
, invisibly.
read_lines(file.path(R.home("doc"), "AUTHORS"), n_max = 10)
read_lines_raw(file.path(R.home("doc"), "AUTHORS"), n_max = 10)
tmp <- tempfile()
write_lines(rownames(mtcars), tmp)
read_lines(tmp, lazy = FALSE)
read_file(tmp) # note trailing \n
write_lines(airquality$Ozone, tmp, na = "-1")
read_lines(tmp)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.