[R] attr.all.equal() and all.equal(attributes(), attributes())

Heinz Tuechler tuechler at gmx.at
Sun Nov 9 13:24:49 CET 2008


Dear All!

If I try to compare the attributes of two 
objects, I find a surprising behaviour of 
attr.all.equal(). With identical attributes I 
receive the answert NULL. If the attributes 
differ, the answer is as expecxted and differences are shown.
all.equal(attributes(), attributes()) instead 
returns TRUE, if attributes are equal.

See example:

v <- 1:5
attr(v, 'testattribute') <- 'testattribute v'
v_c <- v
attributes(v)
$testattribute
[1] "testattribute v"

attributes(v_c)
$testattribute
[1] "testattribute v"

all.equal(v, v_c)
[1] TRUE
attr.all.equal(v, v_c)
NULL  << - - - - - - - - - - here is, what I don't expected
all.equal(attributes(v), attributes(v_c))
[1] TRUE

attr(v_c, 'testattribute') <- 'testattribute v_c'
attr.all.equal(v, v_c)
[1] "Attributes: < Component 1: 1 string mismatch >"
all.equal(attributes(v), attributes(v_c))
[1] "Component 1: 1 string mismatch"

Thanks for your attention

Heinz Tüchler

Version:
  platform = i386-pc-mingw32
  arch = i386
  os = mingw32
  system = i386, mingw32
  status = Patched
  major = 2
  minor = 8.0
  year = 2008
  month = 11
  day = 04
  svn rev = 46830
  language = R
  version.string = R version 2.8.0 Patched (2008-11-04 r46830)

Windows XP (build 2600) Service Pack 2

Locale:
LC_COLLATE=German_Austria.1252;LC_CTYPE=German_Austria.1252;LC_MONETARY=German_Austria.1252;LC_NUMERIC=C;LC_TIME=German_Austria.1252

Search Path:
  .GlobalEnv, package:stats, package:graphics, 
package:grDevices, package:utils, 
package:datasets, package:methods, Autoloads, package:base



More information about the R-help mailing list