The R Project SVN R

Rev

Rev 68948 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 68948 Rev 70730
Line 1... Line 1...
1
% File src/library/base/man/raw.Rd
1
% File src/library/base/man/raw.Rd
2
% Part of the R package, https://www.R-project.org
2
% Part of the R package, https://www.R-project.org
3
% Copyright 2004-2014 R Core Team
3
% Copyright 2004-2016 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{raw}
6
\name{raw}
7
\alias{raw}
7
\alias{raw}
8
\alias{as.raw}
8
\alias{as.raw}
Line 57... Line 57...
57
}
57
}
58
\examples{
58
\examples{
59
xx <- raw(2)
59
xx <- raw(2)
60
xx[1] <- as.raw(40)     # NB, not just 40.
60
xx[1] <- as.raw(40)     # NB, not just 40.
61
xx[2] <- charToRaw("A")
61
xx[2] <- charToRaw("A")
-
 
62
xx       ## 28 41   -- raw prints hexadecimals
-
 
63
dput(xx) ## as.raw(c(0x28, 0x41))
62
xx
64
as.integer(xx) ## 40 65
63
 
65
 
64
x <- "A test string"
66
x <- "A test string"
65
(y <- charToRaw(x))
67
(y <- charToRaw(x))
66
is.vector(y) # TRUE
68
is.vector(y) # TRUE
67
rawToChar(y)
69
rawToChar(y)
68
is.raw(x)
70
is.raw(x)
69
is.raw(y)
71
is.raw(y)
-
 
72
stopifnot( charToRaw("\xa3") == as.raw(0xa3) )
70
 
73
 
71
isASCII <-  function(txt) all(charToRaw(txt) <= as.raw(127))
74
isASCII <-  function(txt) all(charToRaw(txt) <= as.raw(127))
72
isASCII(x)  # true
75
isASCII(x)  # true
73
isASCII("\x9c25.63") # false (in Latin-1, this is an amount in UK pounds)
76
isASCII("\xa325.63") # false (in Latin-1, this is an amount in UK pounds)
74
}
77
}
75
\keyword{classes}
78
\keyword{classes}