volkmar.klatt at bnv-bamberg.de
2008-Apr-07 21:10 UTC
[Rd] "\0" gives no warning "unknown escape sequence" (PR#11107)
Full_Name: Volkmar Klatt
Version: 2.6.2
OS: linux
Submission from: (NULL) (84.147.0.178)
Hello,
the documentation article
?Quotes
from package:base could be improved by discussing
the meaning of "\0" escape sequence.
In R (currently used: R-2.6.2), a "\0" in a string will
silently terminate that string, just as it would in C code.
There is no warning about an unknown escape sequence.
(cf. R FAQ 7.37)
# example:
s <- "abc\0def"
s
# --> [1] "abc"
nchar(s)
# --> [1] 3
The "\0" seems to be so fundamental, that it cannot be handled by
any R function, am I right?
E.g., the function escapeBS (package:Hmisc) does not correctly
handle "\0" sequences, that is in contrast to what is stated in its
article ?escapeBS :
"'escapeBS' will escape any backslash '\backslash' in a
string.
# example:
library(Hmisc)
escapeBS("abc\0def")
# -->[1] "abc"
Bye,
Volkmar Klatt
volkmar.klatt AT bnv-bamberg.de
Uwe Ligges
2008-Apr-08 11:21 UTC
[Rd] "\0" gives no warning "unknown escape sequence" (PR#11107)
volkmar.klatt at bnv-bamberg.de wrote:> Full_Name: Volkmar Klatt > Version: 2.6.2 > OS: linux > Submission from: (NULL) (84.147.0.178) > > > Hello, > > the documentation article > ?Quotes > from package:base could be improved by discussing > the meaning of "\0" escape sequence. > In R (currently used: R-2.6.2), a "\0" in a string will > silently terminate that string, just as it would in C code. > There is no warning about an unknown escape sequence. > (cf. R FAQ 7.37)So having read that, I do expect the behavior you write about below. Best wishes, Uwe> # example: > s <- "abc\0def" > s > # --> [1] "abc" > nchar(s) > # --> [1] 3 > > The "\0" seems to be so fundamental, that it cannot be handled by > any R function, am I right? > E.g., the function escapeBS (package:Hmisc) does not correctly > handle "\0" sequences, that is in contrast to what is stated in its > article ?escapeBS : > "'escapeBS' will escape any backslash '\backslash' in a string. > > # example: > library(Hmisc) > escapeBS("abc\0def") > # -->[1] "abc" > > Bye, > Volkmar Klatt > volkmar.klatt AT bnv-bamberg.de > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
Duncan Murdoch
2008-Apr-08 11:41 UTC
[Rd] "\0" gives no warning "unknown escape sequence" (PR#11107)
volkmar.klatt at bnv-bamberg.de wrote:> Full_Name: Volkmar Klatt > Version: 2.6.2 > OS: linux > Submission from: (NULL) (84.147.0.178) > > > Hello, > > the documentation article > ?Quotes > from package:base could be improved by discussing > the meaning of "\0" escape sequence. >I agree...> In R (currently used: R-2.6.2), a "\0" in a string will > silently terminate that string, just as it would in C code. > There is no warning about an unknown escape sequence. > (cf. R FAQ 7.37) > > # example: > s <- "abc\0def" > s > # --> [1] "abc" > nchar(s) > # --> [1] 3 > > The "\0" seems to be so fundamental, that it cannot be handled by > any R function, am I right? >Not quite. The parser will stop parsing a string when it hits one, but you could embed one in a string using something like > rawToChar(as.raw(c(97:99, 0, 100:102))) [1] "abc\0def"> E.g., the function escapeBS (package:Hmisc) does not correctly > handle "\0" sequences, that is in contrast to what is stated in its > article ?escapeBS : > "'escapeBS' will escape any backslash '\backslash' in a string. > >But there was no backslash in that string, escapeBS only saw the "abc" part that the parser gave it. I don't know that the parser should be able to handle input like "abc\0def", but it does make sense that it would, since that's a legal character vector. Duncan Murdoch> # example: > library(Hmisc) > escapeBS("abc\0def") > # -->[1] "abc" > > Bye, > Volkmar Klatt > volkmar.klatt AT bnv-bamberg.de > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >