read_all: Read all text files and concatenate their content

View source: R/io.R

read_allR Documentation

Read all text files and concatenate their content

Description

Read files one by one, and optionally add text before/after the content. Then combine all content into one character vector.

Usage

read_all(files, before = function(f) NULL, after = function(f) NULL)

Arguments

files

A vector of file paths.

before, after

A function that takes one file path as the input and returns values to be added before or after the content of the file. Alternatively, they can be constant values to be added.

Value

A character vector.

Examples

# two files in this package
fs = system.file("scripts", c("call-fun.R", "child-pids.sh"), package = "xfun")
xfun::read_all(fs)

# add file paths before file content and an empty line after content
xfun::read_all(fs, before = function(f) paste("#-----", f, "-----"), after = "")

# add constants
xfun::read_all(fs, before = "/*", after = c("*/", ""))

xfun documentation built on Nov. 17, 2022, 1:06 a.m.