Read/write lines to/from a file
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 = -1L, locale = default_locale(), na = character(), progress = show_progress() ) read_lines_raw(file, skip = 0, n_max = -1L, progress = show_progress()) write_lines( x, file, sep = "\n", na = "NA", append = FALSE, 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. It must contain at least one new line to be recognised as data (instead of a path) or be a vector of greater than length 1. 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 |
progress |
Display a progress bar? By default it will only display
in an interactive session and not while knitting a document. The display
is updated every 50,000 values and will only display if estimated reading
time is 5 seconds or more. 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) read_file(tmp) # note trailing \n write_lines(airquality$Ozone, tmp, na = "-1") read_lines(tmp)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.