Attach Method for Data Frame Objects

DESCRIPTION:
Attaches a data frame object to the search path.

USAGE:
attach.data.frame(what, use.names=T,
                  name=deparse(substitute(what))[[1]], ...)
attach.pframe(what, ..., name=deparse(substitute(what))[[1]])

REQUIRED ARGUMENTS:
what:
a data frame object.

OPTIONAL ARGUMENTS:
use.names:
should the variables in the attached database have as names the row names of the data frame. These names may be useful for plotting, printing, etc. For large objects, however, considerable extra computation is incurred by having names attributes on all the variables. For such objects, it may be preferable to suppress the use of row names as names.
name:
the name to use for the object in search(). By default, the argument is substituted and deparsed.
...:
other arguments to attach.default.

SIDE EFFECTS:
what is attached to the search list.

DETAILS:
These functions are methods for the generic function attach for classes data.frame and pframe. The data.frame method optionally assigns the row names of the data frame to each of the variables as names (or as part of the dimnames if the variable is a matrix).

The pframe method differs only in that it first includes all components of the parameter attribute as variables, before attaching the resulting object. Thus, both the variables in the data frame and the parameters are accessible by name from the attached database.


HINT:
Attaching a data frame in position 1 is a good way to do a few quick changes. Save the modified frame as in the example below, when detaching it. For more than a few changes, or in the case that you aren't quite sure what changes to make, this approach can cause clutter. Either check carefully for the objects() before detaching, removing all the junk, or else attach in position 2 and explicitly create new variables for the data frame via assign().

WARNING:
Odd behavior can occur after attaching a data frame to position 1. After you make changes to the data frame, you should immediately detach it from position 1 in the search path. Attached S-PLUS objects work best as read-only databases, and in most cases, should be attached in a position other than position 1.

SEE ALSO:
attach , data.frame.object , pframe.object .

EXAMPLES:
# attach a data frame as working data
# note that pos=1 is passed down to attach.default()
attach(fuel.frame, pos=1)
h <- Weight/Disp. # a new variable
detach(1, save="new.fuel.frame")