Learn R Programming

readr (version 0.2.0)

read_lines: Read lines from a file or string.

Description

Read lines from a file or string.

Usage

read_lines(file, skip = 0, n_max = -1L, locale = default_locale(), progress = interactive())
read_lines_raw(file, skip = 0, n_max = -1L, progress = interactive())

Arguments

file
Either a path to a file, a connection, or literal data (either a single string or a raw vector).

Files ending in .gz, .bz2, .xz, or .zip will be automatically uncompressed. Files starting with http://, https://, ftp://, or ftps:// will be automatically downloaded. Remote gz files can also be automatically downloaded & decompressed.

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).

skip
Number of lines to skip before reading data.
n_max
Number of lines to read. If n is -1, all lines in file will be read.
locale
The locale controls defaults that vary from place to place. The default locale is US-centric (like R), but you can use locale to create your own locale that controls things like the default time zone, encoding, decimal mark, big mark, and day/month names.
progress
Display a progress bar? By default it will only display in an interactive session. The display is updated every 50,000 values and will only display if estimated reading time is 5 seconds or more.

Value

A character vector with one element for each line.

Examples

Run this code
read_lines(system.file("extdata/mtcars.csv", package = "readr"))
read_lines("1\n\n2")
read_lines("\n")

read_lines_raw(system.file("extdata/mtcars.csv", package = "readr"))

Run the code above in your browser using DataLab