R: Convert to and from 'emmGrid' objects

as.emmGrid {emmeans} | R Documentation

## Convert to and from `emmGrid` objects

### Description

These are useful utility functions for creating a compact version of an `emmGrid` object that may be saved and later reconstructed, or for converting old `ref.grid` or `lsmobj` objects into `emmGrid` objects.

### Usage

    as.emmGrid(object, ...)

    ## S3 method for class 'emmGrid'
    as.list(x, ...)

### Arguments

`object` | Object to be converted to class `emmGrid`. It may be a `list` returned by `as.list.emmGrid`, or a `ref.grid` or `lsmobj` object created by emmeans's predecessor, the lsmeans package. An error is thrown if `object` cannot be converted.
`...` | In `as.emmGrid`, additional arguments passed to `update.emmGrid` before returning the object. This argument is ignored in `as.list.emmGrid`
`x` | An `emmGrid` object

### Details

An `emmGrid` object is an S4 object, and as such cannot be saved in a text format or saved without a lot of overhead. By using `as.list`, the essential parts of the object are converted to a list format that can be easily and compactly saved for use, say, in another session or by another user. Providing this list as the arguments for `emmobj` allows the user to restore a working `emmGrid` object.

### Value

`as.emmGrid` returns an object of class `emmGrid`.

`as.list.emmGrid` returns an object of class `list`.

### See Also

`emmobj`

### Examples

    pigs.lm <- lm(log(conc) ~ source + factor(percent), data = pigs)
    pigs.sav <- as.list(ref_grid(pigs.lm))

    pigs.anew <- as.emmGrid(pigs.sav)
    emmeans(pigs.anew, "source")

    ## Not run:
    ## Convert an entire workspace saved from an old **lsmeans** session
    a.problem <- lsmeans::lsmeans(pigs.lm, "source")
    #- Now global env contains at least two ref.grid and lsmobj objects,
    #- and the "lsmeans" namespace is loaded
    emmeans:::convert_workspace()
    class(a.problem)
    "lsmeans" %in% loadedNamespaces()
    #- It's all better now

    ## End(Not run)

[Package emmeans version 1.1.3 Index]