getters {AMModels}R Documentation

Extract A Single Model or Data Object, Get Or Set Info, Description, Or Metadata.


The function getAMData will extract an amData object from an amModelLib; the function getAMModel will extract an amModel object from an amModelLib. The function ammlDesc can be used to retrieve or set a description of an amModelLib object. The function ammlInfo can be used to retrieve or set information about an amModelLib object. modelMeta and dataMeta retrieve and set metadata within amModelLib objects.


getAMModel(amml, x, as.list = FALSE, ...)

getAMData(amml, x, as.list = FALSE, ...)


ammlDesc(amml) <- value

ammlInfo(amml, x = NULL)

ammlInfo(amml) <- value

modelMeta(amml, x = NULL)

modelMeta(amml, x) <- value

dataMeta(amml, x = NULL)

dataMeta(amml, x) <- value



An amModelLib object.


A name or length 1 integer index to extract from or set within the amModelLib object.


Logical; FALSE to return just the object, TRUE to return a list with both object and metadata.


Additional arguments (not used).


A named list of metadata to set within x.


The objects created by getAMData and getAMModel are returned as their original class unless the argument as.list is set to TRUE. If as.list, a list is returned with the original object in the first element and metadata in the second.
The setters for ammlInfo, modelMeta, and dataMeta replace individual elements in their respective lists with each call. To remove elements set their value to NULL in the named replacement list.


The model or data object in its original form, or if as.list a list with


The original model



The original data

) and




See Also

Other amModelLib: AMModels, amData, amModelLib, amModel, grepAMModelLib, insertAMModelLib, lsModels, rmModel


# create dataset from lm helpfile
## Annette Dobson (1990) "An Introduction to Generalized Linear Models".
## Page 9: Plant Weight Data.
# notice the models lm.D9 and lm.D90 are of class 'lm'
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
lm.D90 <- lm(weight ~ group - 1) # omitting intercept

# create two amModel objects with metadata and a soft link to the data
full.model <- amModel(
    model = lm.D9, 
    comment = 'full model', 
    source = 'lm helpfile (R).', 
    taxa = 'plants', 
    data = ''
) <- amModel(
    model = lm.D90, 
    comment = 'model without intercept', 
    source = 'lm helpfile (R).', 
    taxa = 'plants', 
    data = ''

# create an amData object that includes metadata
# the is of class data.frame <- data.frame(group = group, weight = weight) <- amData(
    data =, 
    comment = 'Dataset from lm helpfile.'

# create a second amData object that includes metadata <- data.frame(group, log.weight=log(weight)) <- amData(
    data =, 
    comment = 'data to fit log model', 
    source = 'lm helpfile (R).'

# create an amModelLib that contains the two amModel objects and two amData objects
# the models and data must be supplied as named lists
mymodels <- amModelLib(
    models = list(
        full.model = full.model, =
    data = list( =, =

# extract the dataset
getAMData(amml = mymodels, '', as.list = FALSE)

# you can also extract by index
getAMData(amml = mymodels, 1, as.list = FALSE)

# extract the model
getAMModel(amml = mymodels, 'full.model', as.list = FALSE)

# you can also extract by index
getAMModel(amml = mymodels, 1, as.list = FALSE)
# extraction with '[' and '[[', which are identical here, focus on models

# Add a description to the amModelLib
ammlDesc(mymodels) <- "This library demonstrates how to store models 
and data in a format that allows for descriptive metadata and easy 
retrieval for future reference."

# Extract the description

# Add some metadata 'info' to the amModelLib
ammlInfo(mymodels) <- list(owner = 'me', organization = 'My Organization')

# Extract all info for an amModelLib

# Extract targeted info
ammlInfo(amml = mymodels, 'owner')

# Delete metadata by setting to NULL
ammlInfo(mymodels) <- list(organization = NULL)

# Extract all model metadata

# Extract metadata from specific model
modelMeta(amml = mymodels, 'full.model')

# Add metadata to 'full.model'
modelMeta(amml = mymodels, 'full.model') <- list(
    url = ""

# remove metadata by setting value to NULL
modelMeta(amml = mymodels, 'full.model') <- list(url = NULL)

# Extract all data metadata

# Extract metadata from specific data
dataMeta(amml = mymodels, '')

# Add metadata to ''
dataMeta(mymodels, '') <- list(
    url = ""

# remove metadata by setting value to NULL
dataMeta(mymodels, '') <- list(url = NULL)

[Package AMModels version 0.1.4 Index]