The R Project SVN R

Rev

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

Rev 68948 Rev 70664
Line 1... Line 1...
1
% File src/library/base/man/identical.Rd
1
% File src/library/base/man/identical.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 2001-2014 R Core Team
3
% Copyright 2001-2016 R Core Team
4
% Distributed under GPL 2 or later
4
% Distributed under GPL 2 or later
5
 
5
 
6
\name{identical}
6
\name{identical}
7
\alias{identical}
7
\alias{identical}
8
\title{Test Objects for Exact Equality}
8
\title{Test Objects for Exact Equality}
Line 11... Line 11...
11
  \emph{exactly} equal.  It returns \code{TRUE} in this case,
11
  \emph{exactly} equal.  It returns \code{TRUE} in this case,
12
  \code{FALSE} in every other case.
12
  \code{FALSE} in every other case.
13
}
13
}
14
\usage{
14
\usage{
15
identical(x, y, num.eq = TRUE, single.NA = TRUE, attrib.as.set = TRUE,
15
identical(x, y, num.eq = TRUE, single.NA = TRUE, attrib.as.set = TRUE,
16
          ignore.bytecode = TRUE, ignore.environment = FALSE)
16
          ignore.bytecode = TRUE, ignore.environment = FALSE,
-
 
17
          ignore.srcref = TRUE)
17
}
18
}
18
\arguments{
19
\arguments{
19
  \item{x, y}{any \R objects.}
20
  \item{x, y}{any \R objects.}
20
  \item{num.eq}{logical indicating if (\code{\link{double}} and
21
  \item{num.eq}{logical indicating if (\code{\link{double}} and
21
    \code{\link{complex}} non-\code{\link{NA}}) numbers should be
22
    \code{\link{complex}} non-\code{\link{NA}}) numbers should be
Line 32... Line 33...
32
    \code{attrib.as.set = FALSE}.}
33
    \code{attrib.as.set = FALSE}.}
33
  \item{ignore.bytecode}{logical indicating if byte code should be
34
  \item{ignore.bytecode}{logical indicating if byte code should be
34
    ignored when comparing \link{closure}s.}
35
    ignored when comparing \link{closure}s.}
35
  \item{ignore.environment}{logical indicating if their environments
36
  \item{ignore.environment}{logical indicating if their environments
36
    should be ignored when comparing \link{closure}s.}
37
    should be ignored when comparing \link{closure}s.}
-
 
38
  \item{ignore.srcref}{logical indicating if their \code{"srcref"}
-
 
39
    attributes should be ignored when comparing \link{closure}s.}
37
}
40
}
38
\details{
41
\details{
39
  A call to \code{identical} is the way to test exact equality in
42
  A call to \code{identical} is the way to test exact equality in
40
  \code{if} and \code{while} statements, as well as in logical
43
  \code{if} and \code{while} statements, as well as in logical
41
  expressions that use \code{&&} or \code{||}.  In all these
44
  expressions that use \code{&&} or \code{||}.  In all these
Line 128... Line 131...
128
identical(0., -0.) # TRUE, i.e. not differentiated
131
identical(0., -0.) # TRUE, i.e. not differentiated
129
identical(0., -0., num.eq = FALSE)
132
identical(0., -0., num.eq = FALSE)
130
## similar:
133
## similar:
131
identical(NaN, -NaN) # TRUE
134
identical(NaN, -NaN) # TRUE
132
identical(NaN, -NaN, single.NA = FALSE) # differ on bit-level
135
identical(NaN, -NaN, single.NA = FALSE) # differ on bit-level
-
 
136
 
-
 
137
### For functions ("closure"s): ----------------------------------------------
133
## for functions:
138
###     ~~~~~~~~~
134
f <- function(x) x
139
f <- function(x) x
135
f
140
f
136
g <- compiler::cmpfun(f)
141
g <- compiler::cmpfun(f)
137
g
142
g
-
 
143
identical(f, g)                        # TRUE, as bytecode is ignored by default
-
 
144
identical(f, g, ignore.bytecode=FALSE) # FALSE: bytecode differs
-
 
145
 
-
 
146
## GLM families contain several functions, some of which share an environment:
-
 
147
p1 <- poisson() ; p2 <- poisson()
-
 
148
identical(p1, p2)                          # FALSE
-
 
149
identical(p1, p2, ignore.environment=TRUE) # TRUE
-
 
150
 
-
 
151
## in interactive use, the 'keep.source' option is typically true:
-
 
152
op <- options(keep.source = TRUE) # and so, these have differing "srcref" :
-
 
153
f1 <- function() {}
138
identical(f, g)
154
f2 <- function() {}
-
 
155
identical(f1,f2)# ignore.srcref= TRUE : TRUE
139
identical(f, g, ignore.bytecode = FALSE)
156
identical(f1,f2,  ignore.srcref=FALSE)# FALSE
-
 
157
options(op) # revert to previous state
-
 
158
 
140
\dontshow{
159
\dontshow{
141
m0 <- m <- structure(cbind(I = 1, a = 1:3), foo = "bar", class = "matrix")
160
m0 <- m <- structure(cbind(I = 1, a = 1:3), foo = "bar", class = "matrix")
142
attributes(m0) <- rev(attributes(m))
161
attributes(m0) <- rev(attributes(m))
143
names(attributes(m0)) # 'dim' remains first, interestingly...
162
names(attributes(m0)) # 'dim' remains first, interestingly...
144
 
163