[R] Fwd: string
Gabor Grothendieck
ggrothendieck at gmail.com
Wed Jan 6 12:43:55 CET 2010
Some new syntax to handle this without escapes was on my wish list for
R and keeps coming up from time to time. As mentioned it would also be
useful for latex source, Windows path names, regular expressions and
other situations such as this one which require characters that
otherwise need to be escaped.
On Wed, Jan 6, 2010 at 6:33 AM, Peter Dalgaard <P.Dalgaard at biostat.ku.dk> wrote:
> robert-mcfadden at o2.pl wrote:
>> I would like to assign a variable y the string: <question><span style="color: #0000FF; font-weight: bold; font-size: 14pt">
>> How can I do it - is it possible?
>
> Sure, but you need to escape the double quotes.
>
> The easiest way is actually to read it in, like (sorry about the line
> breakage...)
>
>> x <- readLines(n=1)
> <question><span style="color: #0000FF; font-weight: bold; font-size: 14pt">
>> x
> [1] "<question><span style=\"color: #0000FF; font-weight: bold;
> font-size: 14pt\">"
>
> but you could also assign directly
>
>> y <- "<question><span style=\"color: #0000FF; font-weight: bold;
> font-size: 14pt\">"
>> x == y
> [1] TRUE
>
> (Notice that the backslashes are not actually part of the string, it is
> just that internal quotes are _displayed_ as \", and entered in the same
> way. This tends to confuse people at first.)
>
> --
> O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
> c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
>
> ______________________________________________
> 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