Attach Method for Data Frame Objects

DESCRIPTION:

Attaches a data frame object to the search path.

USAGE:

attach.data.frame(what, pos, name, purpose) 
attach.pframe(what, pos, name, purpose) 

REQUIRED ARGUMENTS:

what
a data frame object.

OPTIONAL ARGUMENTS:

pos
position in the search list that what should occupy. The data directories originally in position pos or beyond are moved down the list after what. If pos=1, what is attached as the working directory (you must have write permission on the corresponding object or directory). If pos is a large number (.Machine$integer.max is guaranteed big enough), the new database is attached at the end of the search path. The position can be given as that of an attached database, either by name or as an attached object; the new database is then inserted just in front of the specified database.
name
the name to use for the object in search(). By default, the name is constructed from the what argument.
purpose
the purpose of the database, by default for search.
...
other arguments to attach.default.

VALUE:

the attached data frame, as an object of class "attached". This uniquely identifies the data frame as a database. This return value is the best object to specify the database as a where argument to get, exists, etc. If you attach a data frame on two occasions, you get two distinct identifications.

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 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.
Assignments to an attached object are allowed in any position, provided you have write permission. The underlying object is not updated until the object itself is removed from the search list, either through detach or by quitting S-PLUS. At that time, the revised object is written back to the file from which it came at the time it was attached. The search list is valid only for the current S-PLUS session, that is, it does not persist from session to session.

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:

, , , .

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")