[R] do not execute newline command
Kenn Konstabel
lebatsnok at gmail.com
Tue Apr 5 10:27:39 CEST 2011
On Tue, Apr 5, 2011 at 10:40 AM, Lorenzo Cattarino
<l.cattarino at uq.edu.au> wrote:
> Hi R-users,
>
> To automate the creation of scripts, I converted the code (example below) into a character string and wrote the object to a file:
>
> Repeat <- "
> myvec <- c(1:12)
> cat('vector= ', myvec, '\n')
> "
>
> write (Repeat, 'yourpath/test.R')
>
> the problem is that one line of the code is a "cat" command. In the output file (i.e. test.R), the newline symbol gets executed and I don't want that.
>
> Any idea on how to do that?
You can "escape" the newline symbol (i.e., write an extra \ before it):
Repeat <- "
myvec <- c(1:12)
cat('vector= ', myvec, '\\n')
"
write (Repeat, 'test.R')
> Thanks
> Lorenzo
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list