1

I am trying to write a text file. I like using the cat() function because it makes writing line breaks really easy. However, I noticed I can't seem to save the character string as a variable in the global environment. I just get "lines" equal to NULL. How can it be saved as the character string (with line breaks) that it returns without being saved to a variable?

lines <- cat(paste("",
                   "",
                   "",
                   "",
                   "this is line 4",sep="\n"))
hmnoidk
  • 545
  • 6
  • 20
  • 3
    `cat` is for _output_ to a _connection_. While you _could_ have it create an R object to store the character output to, why aren't you just using `paste`/`paste0`? They have a `collapse` parameter. – hrbrmstr Dec 03 '18 at 19:32
  • 2
    I can't figure out what you are trying to do either. Maybe this will help: https://stackoverflow.com/questions/31843662/what-is-the-difference-between-cat-and-print – MrFlick Dec 03 '18 at 19:38
  • I couldn't figure out how to break lines with the paste functions. However, the link showed me that you can write directly to a file with cat, which is ultimately what I was trying to do, so thank you. :) – hmnoidk Dec 03 '18 at 20:25

0 Answers0