[R] Accessing just the value of an object but not the attributes

Martin Maechler maechler at stat.math.ethz.ch
Tue Oct 2 17:21:02 CEST 2001

>>>>> "Johann" == Johann Petrak <johann at ai.univie.ac.at> writes:

    Johann> I have the feeling that this is a dumb question but oh well ...
no, actually not at all dumb

    Johann> When I have an object x with several attributes, y <- x will
    Johann> make a copy of x with all the attributes included.  What if I
    Johann> just want y to get the value assigned but nothing else (no
    Johann> class, names, dim or other attributes)?

The answer -- `unfortunately' IMHO --- 
is  as.vector() :

>> Description:
>>      `vector' .......
>>      `as.vector', a generic, attempts to coerce its argument into a
>>      vector of mode `mode' (the default is to coerce to whichever mode
>>      is most convenient).  The attributes of `x' are removed.

"unfortunately" : 
		IMO, a vector with attributes is still a vector, particularly
		if these are just names.. hence as.vector() should leave it
		alone, but -- alas -- it's for compatibility reasons too
		important to be changed. 
So even if a new  dropattributes() function would do what as.vector() does
now, it would break too much code if as.vector() was changed...
Note that "unfortunately" is my personal opinion, not a general R core one.

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list