[ RDocumentation ](/)

Moon  [ ](https://github.com/datacamp/rdocumentation-2.0) [ Learn R
](https://www.datacamp.com/learn/r)

Search all packages and functions

[ base  (version  3.6.2  ) ](/packages/base/versions/3.6.2)

#  mode: The (Storage) Mode of an Object

##  Description

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

##  Usage

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

##  Arguments

x

any  R  object.

value

a character string giving the desired mode or ‘storage mode’ (type) of the
object.

##  Mode names

Modes have the same set of names as types (see ` [ typeof
](/link/typeof?package=base&version=3.6.2) ` ) except that

  * types ` "integer" ` and ` "double" ` are returned as ` "numeric" ` . 

  * types ` "special" ` and ` "builtin" ` are returned as ` "function" ` . 

  * type ` "symbol" ` is called mode ` "name" ` . 

  * type ` "language" ` is returned as ` "(" ` or ` "call" ` . 

##  Details

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 ](/link/typeof?package=base&version=3.6.2) (x) ` , see the
example below.

` mode(x) <- "newmode" ` changes the ` mode ` of object ` x ` to ` newmode ` .
This is only supported if there is an appropriate ` as.newmode ` function, for
example ` "logical" ` , ` "integer" ` , ` "double" ` , ` "complex" ` , ` "raw"
` , ` "character" ` , ` "list" ` , ` "expression" ` , ` "name" ` , ` "symbol"
` and ` "function" ` . Attributes are preserved (but see below).

` storage.mode(x) <- "newmode" ` is a more efficient [ primitive
](/link/primitive?package=base&version=3.6.2) version of ` mode<- ` , which
works for ` "newmode" ` which is one of the internal types (see ` [ typeof
](/link/typeof?package=base&version=3.6.2) ` ), but not for ` "single" ` .
Attributes are preserved.

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, ` mode<- ` 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
](/link/call?package=base&version=3.6.2) ` s have mode ` "(" ` which is S
compatible.

##  References

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

##  See Also

` [ typeof ](/link/typeof?package=base&version=3.6.2) ` for the R-internal
‘mode’, ` [ type.convert
](/link/type.convert?package=base&version=3.6.2&to=utils) ` , ` [ attributes
](/link/attributes?package=base&version=3.6.2) ` .

##  Examples

[ Run this code
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fmode&utm_source=r-docs&utm_medium=docs&utm_term=mode&utm_content=run_example_in_workspace)

    
    
    # NOT RUN {
    require(stats)
    
    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)
    # }
    

Run the code above in your browser using  [ DataCamp Workspace
](https://app.datacamp.com/workspace/preview?_tag=rdocs&rdocsPath=packages%2Fbase%2Fversions%2F3.6.2%2Ftopics%2Fmode&utm_source=r-docs&utm_medium=docs&utm_term=mode&utm_content=run_example_in_workspace)

Powered by