[R] can I paste 'newline'?

jim holtman jholtman at gmail.com
Fri Jul 20 01:52:10 CEST 2007


Notice the difference:

> cat ('I need to move on to a new line', '\n', 'at here') # change line!
I need to move on to a new line
 at here> paste ('I need to move on to a new line', '\n', 'at here') #
'\n' is just a
[1] "I need to move on to a new line \n at here"
> cat(paste ('I need to move on to a new line', '\n', 'at here'))
I need to move on to a new line
 at here>

> paste("a long string
+ with carriage
+ returns")
[1] "a long string\nwith carriage\nreturns"
>
>
> cat(paste("a long string
+ with carriage
+ returns"))
a long string
with carriage
returns>


paste is showing you the characters in the string; cat is acutally
outputting to a print device where '\n' is a line feed.

On 7/19/07, runner <sunnyside500 at gmail.com> wrote:
>
> It is ok to bury a reg expression '\n' when using 'cat', but not 'paste'.
> e.g.
>
> cat ('I need to move on to a new line', '\n', 'at here') # change line!
> paste ('I need to move on to a new line', '\n', 'at here') # '\n' is just a
> character as it is.
>
> Is there a way around pasting '\n' ? Thanks a lot.
> --
> View this message in context: http://www.nabble.com/can-I-paste-%27newline%27--tf4114350.html#a11699845
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list