mode                  package:base                  R Documentation

_T_h_e (_S_t_o_r_a_g_e) _M_o_d_e _o_f _a_n _O_b_j_e_c_t

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

     Get or set the type or storage mode of an object.

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

     mode(x)
     mode(x) <- value
     storage.mode(x)
     storage.mode(x) <- value

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

       x: any R object.

   value: a character string giving the desired (storage) mode of the
          object.

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

     Both 'mode' and 'storage.mode' return a character string giving
     the (storage) mode of the object - often the same - both relying
     on the output of 'typeof(x)', see the example below.

     The two assignment versions are currently identical.  Both
     'mode(x) <- newmode' and 'storage.mode(x) <- newmode' change the
     'mode' or 'storage.mode' of object 'x' to 'newmode'.

     As storage mode '"single"' is only a pseudo-mode in R, it will not
     be reported by 'mode' or 'storage.mode': use 'attr(object,
     "Csingle")' to examine this. However, the assignment versions can
     be used to set the mode to '"single"', which sets the real mode to
     '"double"' and the '"Csingle"' attribute to 'TRUE'. Setting any
     other mode will remove this attribute.

     Note (in the examples below) that some 'call's have mode '"("'
     which is S compatible.

_R_e_f_e_r_e_n_c_e_s:

     Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) _The New S
     Language_. Wadsworth & Brooks/Cole.

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

     'typeof' for the R-internal "mode", 'attributes'.

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

     sapply(options(),mode)

     cex3 <- c("NULL","1","1:1","1i","list(1)","data.frame(x=1)", "pairlist(pi)",
       "c", "lm", "formals(lm)[[1]]",  "formals(lm)[[2]]",
       "y~x","expression((1))[[1]]", "(y~x)[[1]]", "expression(x <- pi)[[1]][[1]]")
     lex3 <- sapply(cex3, function(x) eval(parse(text=x)))
     mex3 <- t(sapply(lex3, function(x) c(typeof(x), storage.mode(x), mode(x))))
     dimnames(mex3) <- list(cex3, c("typeof(.)","storage.mode(.)","mode(.)"))
     mex3

     ## This also makes a local copy of 'pi':
     storage.mode(pi) <- "complex"
     storage.mode(pi)
     rm(pi)

