str_write_lines: Write a character vector as lines to a file

View source: R/write-lines.R

str_write_linesR Documentation

Write a character vector as lines to a file

Description

str_write_lines() writes each element of string followed by sep, including the last one, and converts the output to encoding. It is the counterpart of str_read_lines().

Usage

str_write_lines(string, con, encoding = "UTF-8", sep = "\n")

Arguments

string

A character vector to write.

con

A file name or a connection opened in binary mode.

encoding

A single string giving the output encoding. NULL or "" uses the current default encoding.

sep

A single string written after each element. Defaults to "\n" on all platforms.

Details

Missing values are an error. Strings marked with the "bytes" encoding are an error, as in str_c(). Characters that the output encoding cannot represent are written as that encoding's substitution character, with a warning.

Value

string, invisibly and unchanged.

See Also

str_read_lines(); stringi::stri_write_lines(), which writes an empty file instead of signalling an error for missing values.

Examples

path <- tempfile()
str_write_lines(c("first", "second"), path)
str_read_lines(path, encoding = "UTF-8")
unlink(path)

charr documentation built on Nov. 7, 2026, 9:06 a.m.