Write text to a file using writeLines
and output a debug
message by default
Arguments
- x
vector of character representing the lines to be written to
file
, passed towriteLines
- file
path to file to be written, passed to
writeLines
- type
character string to be included in the debug message: "Writing <type>'file-path' ..."
- dbg
if
TRUE
, debug messages are shown- ...
further arguments passed to
writeLines
Examples
# Define text to be written to file
x <- c("Hello", "world")
# Write text to a temporary file and catch the file path
file <- writeText(x, tempfile(fileext = ".txt"))
#> Writing '/var/folders/h1/8hndypj13nsbj5pn4xsnv1tm0000gn/T//Rtmp0pKi4m/filefa3550e98d4.txt' ... ok.
# Make the debug message more informative
writeText(x, file, type = "welcome file")
#> Writing welcome file '/var/folders/h1/8hndypj13nsbj5pn4xsnv1tm0000gn/T//Rtmp0pKi4m/filefa3550e98d4.txt' ... ok.
# Read lines back and show on the console
catLines(readLines(file))
#> Hello
#> world