attach                 package:base                 R Documentation

_A_t_t_a_c_h _S_e_t _o_f _R _O_b_j_e_c_t_s _t_o _S_e_a_r_c_h _P_a_t_h

_D_e_s_c_r_i_p_t_i_o_n:

     The database is attached to the R search path.  This means that
     the database is searched by R when evaluating a variable, so
     objects in the database can be accessed by simply giving their
     names.

_U_s_a_g_e:

     attach(what, pos = 2, name = deparse(substitute(what)))

_A_r_g_u_m_e_n_t_s:

    what: ``database''. This may currently be a `data.frame' or `list'
          or a R data file created with `save'.

     pos: integer specifying position in `search()' where to attach.

    name: alternative way to specify the database to be attached.

_D_e_t_a_i_l_s:

     When evaluating a variable or function name R searches for that
     name in the databases listed by `search'. The first name of the
     appropriate type is used.

     By attaching a data frame to the search path it is possible to
     refer to the variables in the data frame by their names alone,
     rather than as components of the data frame (eg in the example
     below, `height' rather than `women$height').

     By default the database is attached in position 2 in the search
     path, immediately after the R global environment and before all
     previously loaded packages and previously attached databases. This
     can be altered with the `pos' option.

     Note that by default assignment is not performed in an attached
     database. Attempting to modify a variable or function in an
     attached database will actually create a modified version in the R
     global environment. For this reason `attach' can lead to
     confusion.

_V_a_l_u_e:

     The `environment' is returned invisibly with a `"name"' attribute.

_S_e_e _A_l_s_o:

     `library', `detach', `search', `objects', `environment'.

_E_x_a_m_p_l_e_s:

     data(women)
     summary(women$height) ## refers to variable `height' in the dataframe
     attach(women)
     summary(height)      ## The same variable now available by name
     height<-height*2.54  ## Don't do this. It creates a new variable
     detach("women")
     summary(height)      ## The new variable created by modifying `height'
     rm(height)

