slurp: Read a file's lines in as vector

View source: R/fileUtils.R

slurpR Documentation

Read a file's lines in as vector

Description

Essentially a convenience wrapper around readLines. Reads a file's lines into a string vector. Can skip comments if specify a comment string, and drops the header line if told to. Inspired by perl's "slurp" mode.

Usage

slurp(file, commentString = NULL, skipLines = 0)

Arguments

file

The file to read

commentString

If specified, any line beginning with this comment string will be dropped (leading whitespace is ignored). This is parsed as a regular expression, but that shouldn't be a problem for most normal line comment strings ("#", "##", "//", ";"), leading whitespace is ignored. If null or empty, will be ignored. Backslashes probably need to be doubled.

skipLines

If specified, skip this many lines at the start of the file. This will be done after comments are filtered, so don't skip lines if they are also comments.

Value

The file's content as a string vector, one element per line, including empty lines as empty strings, but excluding filtered lines. If no lines are left after dropping comments and skipping the headers, will return character(0)

Warnings

Skipping more lines, skip, than lines to skip, lines.

There are fewer lines left (after skipping comments) than you asked to skip. Will return character(0) to indicate no kept lines/strings.


jefferys/JefferysRUtils documentation built on June 18, 2024, 4:39 a.m.