slot package:methods R Documentation _T_h_e _S_l_o_t_s _i_n _a_n _O_b_j_e_c_t _f_r_o_m _a _F_o_r_m_a_l _C_l_a_s_s _D_e_s_c_r_i_p_t_i_o_n: These functions return or set information about the individual slots in an object. _U_s_a_g_e: object@name object@name <- value slot(object, name) slot(object, name, check = TRUE) <- value slotNames(x) getSlots(x) _A_r_g_u_m_e_n_t_s: object: An object from a formally defined class. name: The name of the slot. The operator takes a fixed name, which can be unquoted if it is syntactically a name in the language. A slot name can be any non-empty string, but if the name is not made up of letters, numbers, and '.', it needs to be quoted (by backticks or single or double quotes). In the case of the 'slot' function, 'name' can be any expression that evaluates to a valid slot in the class definition. Generally, the only reason to use the functional form rather than the simpler operator is _because_ the slot name has to be computed. value: A new value for the named slot. The value must be valid for this slot in this object's class. check: In the replacement version of 'slot', a flag. If 'TRUE', check the assigned value for validity as the value of this slot. User's coded should not set this to 'FALSE' in normal use, since the resulting object can be invalid. x: Either the name of a class or a class definition. If given an argument that is neither a character string nor a class definition, 'slotNames' (only) uses 'class(x)' instead. _D_e_t_a_i_l_s: The definition of the class specifies all slots directly and indirectly defined for that class. Each slot has a name and an associated class. Extracting a slot returns an object from that class. Setting a slot first coerces the value to the specified slot and then stores it. Unlike general attributes, slots are not partially matched, and asking for (or trying to set) a slot with an invalid name for that class generates an error. The '@' extraction operator and 'slot' function themselves do no checking against the class definition, simply matching the name in the object itself. The replacement forms do check (except for 'slot' in the case 'check=FALSE'). So long as slots are set without cheating, the extracted slots will be valid. Be aware that there are two ways to cheat, both to be avoided but with no guarantees. The obvious way is to assign a slot with 'check=FALSE'. Also, slots in R are implemented as attributes, for the sake of some back compatibility. The current implementation does not prevent attributes being assigned, via 'attr<-', and such assignments are not checked for legitimate slot names. _V_a_l_u_e: The '"@"' operator and the 'slot' function extract or replace the formally defined slots for the object. Functions 'slotNames' and 'getSlots' return respectively the names of the slots and the classes associated with the slots in the specified class definition. Except for its extended interpretation of 'x' (above), 'slotNames(x)' is just 'names(getSlots(x))'. _R_e_f_e_r_e_n_c_e_s: Chambers, John M. (2008) _Software for Data Analysis: Programming with R_ Springer. (For the R version.) Chambers, John M. (1998) _Programming with Data_ Springer (For the original S4 version.) _S_e_e _A_l_s_o: '@', 'Classes', 'Methods', 'getClass' _E_x_a_m_p_l_e_s: setClass("track", representation(x="numeric", y="numeric")) myTrack <- new("track", x = -4:4, y = exp(-4:4)) slot(myTrack, "x") slot(myTrack, "y") <- log(slot(myTrack, "y")) utils::str(myTrack) getSlots("track") # or getSlots(getClass("track")) slotNames(class(myTrack)) # is the same as slotNames(myTrack)