I'm not completely clear what you're asking, but it sounds as though you want to write a customer header before you write your pipe delimited file and then add a custom footer.
You can write to a file with the write
function in base R. Use this to write your custom header then use write_delim()
as before but with the append = TRUE
parameter so that the data is added to the file with your header. Finally, use write()
again, but this time also with the append = TRUE
parameter so that footer is added to the existing file.
For example, given you small example data set above, you would do this:
write(
paste0("HD|EIN01|", nrow(employ.data)),
file = "EIN01_Pipe_delimited.txt",
append = FALSE. # Create a new file
)
write_delim(
employ.data, file = "EIN01_Pipe_delimited.txt",
delim = "|",
append = TRUE # Add to the existing file
)
write(
"TR|EIN01",
file = "EIN01_Pipe_delimited.txt",
append = TRUE # Add to the existing file
)