Skip to content
Prev 45696 / 63424 Next

is.vector(as.vector(x, m), m) not always TRUE

In the man page for as.vector() (same as man page for vector()):

      Writers of methods for ?as.vector? need to take care to follow the
      conventions of the default method.  In particular

         ? Argument ?mode? can be ?"any"?, any of the atomic modes,
           ?"list"?, ?"expression"?, ?"symbol"?, ?"pairlist"? or one of
           the aliases ?"double"? and ?"name"?.

         ? The return value should be of the appropriate mode.  For
           ?mode = "any"? this means an atomic vector or list.

         ? Attributes should be treated appropriately: in particular
           when the result is an atomic vector there should be no
           attributes, not even names.

         ? ?is.vector(as.vector(x, m), m)? should be true for any mode
           ?m?, including the default ?"any"?.

But:

   > is.vector(as.vector("a", "name"), "name")
   [1] FALSE

Mmmh, the default method itself doesn't seem to follow its own
conventions :-/

Cheers,
H.

 > sessionInfo()
R version 3.0.0 (2013-04-03)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
  [7] LC_PAPER=C                 LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] tools_3.0.0