as.character("`X^`R\`S")
[1] "`X^`R`S"
Warning messages:
1: '\`' is an unrecognized escape in a character string
2: unrecognized escape removed from "`X^`R\`S"
But I found errors.
Can I use some option in as.character() to change this?
Thanks
Mary
[[alternative HTML version deleted]]
______________________________________________
R-h...@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.
You need to escape the backslash:
> z<- as.character("`X^`R\\`S")
> z
[1] "`X^`R\\`S"
> cat(z)
`X^`R\`S
Bert Gunter
Genentech Nonclinical Statistics
> Hi,
> I want to use a character as below in R,
What character?
>
> as.character("`X^`R\`S")
> [1] "`X^`R`S"
> Warning messages:
> 1: '\`' is an unrecognized escape in a character string
> 2: unrecognized escape removed from "`X^`R\`S"
> nchar("`X^`R\`S")
[1] 7
Warning messages:
1: '\`' is an unrecognized escape in a character string
2: unrecognized escape removed from "`X^`R\`S"
> substr("`X^`R\`S" , 7,7)
[1] "S"
Warning messages:
1: '\`' is an unrecognized escape in a character string
2: unrecognized escape removed from "`X^`R\`S"
> substr("`X^`R\`S" , 6,6)
[1] "`"
Warning messages:
1: '\`' is an unrecognized escape in a character string
2: unrecognized escape removed from "`X^`R\`S"
> substr("`X^`R\`S" , 5,5)
[1] "R"
>
> But I found errors.
> Can I use some option in as.character() to change this?
What do you want? Just to add a back-slash?
> nchar("`X^`R\\`S")
[1] 8
> substr("`X^`R\\`S" , 6,6)
[1] "\\"
Notice that one of the backslashes is not counted because it is not
present in the internal representation. It is, however, printed with
doubling.
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT