metadata.set {opm}R Documentation

Replace metadata

Description

Set the meta-information stored together with the data. For most kinds of arguments the WMDS and MOPMX methods set the meta-information stored together with the measurements for all plates at once. But they can address the plates individually if value is a data frame, and they can address metadata keys individually if value is a formula.

Usage

  ## S4 replacement method for signature 'MOPMX,ANY,ANY'
metadata(object, key) <- value
  ## S4 replacement method for signature 'MOPMX,ANY,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'MOPMX,missing,ANY'
metadata(object, key) <- value
  ## S4 replacement method for signature 'MOPMX,missing,character'
metadata(object, key) <- value
  ## S4 replacement method for signature 'MOPMX,missing,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'MOPMX,missing,logical'
metadata(object, key) <- value
  ## S4 replacement method for signature 'OPM,missing,character'
metadata(object, key) <- value
  ## S4 replacement method for signature 'OPM,missing,logical'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,ANY,ANY'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,character,ANY'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,character,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,character,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,character,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,list,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,list,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,list,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,list,list'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,FOE'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,character'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,missing,list'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,numeric,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,numeric,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,numeric,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMD,numeric,list'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,ANY,ANY'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,ANY,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,ANY,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,ANY,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,character,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,character,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,FOE'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,WMD'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,WMDS'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,character'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,data.frame'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,list'
metadata(object, key) <- value
  ## S4 replacement method for signature 'WMDS,missing,logical'
metadata(object, key) <- value

Arguments

object

WMD, WMDS or MOPMX object.

key

Missing, numeric scalar, character vector, factor, or list.

  • If missing, this mostly means replace all metadata by value, but behaviour is special for some kinds of value arguments. See below for details.

  • If a numeric scalar, then if positive, prepend value to old metadata. If negative, append value to old metadata. If zero, replace old metadata entirely by value.

  • If a list, treated as list of keys; expect value to be a list of corresponding metadata values to be set. Names are replaced by the values of either list if they are missing.

  • If a character vector, used as key for setting/replacing this metadata entry to/by value. It is an error if key has zero length. If it contains more than one entry, a nested query is done. See [[ from the base package for details.

  • The factor method calls the character method after converting key to mode ‘character’.

value

Character vector, list, data frame, formula, WMD or WMDS object. As the metadata are stored as a list, other kinds of objects used as value are special, particularly if key is missing.

  • If key is a character vector, this can be arbitrary value(s) to be included in the metadata (if NULL, this metadata entry is deleted).

  • If key is missing and value is a list but not a data frame, all metadata are replaced by it.

  • If key is missing and value is of mode ‘logical’, TRUE causes all csv_data entries that are not included in opm_opt("csv.selection") to be included in the metadata; FALSE causes these entries, if any, to be removed.

  • If key is missing and value is a character vector and it contains the value given by opm_opt("md.id.name"), then by default a globally unique ID identifying each plate is included in the metadata. Uniqueness only holds per session and can be circumvented by modifying opm_opt("md.id.start"). If value contains the value given by opm_opt("md.duration"), then the overall running time of each plate is included in the metadata. This is useful to select plates based on the total running time, or to include the overall measurement duration as explanatory variable in a model. Other elements of a character vector are not currently supported (they may get a special meaning later on).

  • If key is otherwise, value must be list of values to be prepended, appended or set as metadata, either entirely or specifically, depending on key.

  • Formulae can also be used as value. In that case, the formula can specify the key to be replaced. See the examples below and map_values for details.

  • If object is of class WMDS, value can be a data frame whose number of rows must be equal to the number of plates. Metadata to be set will then be selected from each individual row in turn and in input order. This works analogously if value is an WMDS object. The lengths of both objects must match. If value is a WMD object, its metadata entries will be recycled.

  • If object is of class WMD, value cannot be of class WMD.

Details

This method can easily be used to copy (selected parts of) the csv_data to the metadata; see there for details.

map_metadata can also be used to modify metadata but it will return a novel object. See edit for manually modifying metadata.

Value

value.

See Also

Other metadata-functions: edit, include_metadata, map_metadata, map_values, metadata, metadata_chars

Examples

## WMD methods

# WMD/missing/list method
copy <- vaas_1
new.md <- list(Species = "Thermomicrobium roseum")
metadata(copy) <- new.md
stopifnot(identical(metadata(copy), new.md))

# WMD/missing/formula method (operates on previous entries!)
copy <- vaas_1
metadata(copy) <- Organism ~ paste(Species, Strain)
(x <- metadata(copy, "Organism"))
## [1] "Escherichia coli DSM30083T"
stopifnot(is.null(metadata(vaas_1, "Organism")), !is.null(x))

# WMD/numeric/list method
copy <- vaas_1
metadata(copy, 1) <- list(Authors = "Vaas et al.")
stopifnot(length(metadata(copy)) > length(metadata(vaas_1)))

# WMD/list/list method
copy <- vaas_1
stopifnot(identical(metadata(copy, "Species"), "Escherichia coli"))

# You can use this to translate the keys on-the-fly...
metadata(copy, list(Organism = "Species")) <- list(
  Organism = "Bacillus subtilis")
stopifnot(length(metadata(copy)) == length(metadata(vaas_1)))
stopifnot(identical(metadata(copy, "Species"), "Bacillus subtilis"))
stopifnot(is.null(metadata(copy, "Organism"))) # this was not set!

# ...but you need not
metadata(copy, list("Species")) <- list(Species = "Yersinia pestis")
stopifnot(length(metadata(copy)) == length(metadata(vaas_1)))
stopifnot(identical(metadata(copy, "Species"), "Yersinia pestis"))

# Names need not be duplicated
metadata(copy, list("Species")) <- list("Gen. sp.")
stopifnot(length(metadata(copy)) == length(metadata(vaas_1)))
stopifnot(identical(metadata(copy, "Species"), "Gen. sp."))

# ...but this would delete the entry because nothing would be found in
# 'value'
metadata(copy, list("Species")) <- list(Organism = "E. coli")
stopifnot(length(metadata(copy)) < length(metadata(vaas_1)))
stopifnot(is.null(metadata(copy, "Species")))

# ...this yields a general mechanism for metadata deletion by providing an
# empty list as 'value'.

# WMD/character/any method
copy <- vaas_1
metadata(copy, "Strain") <- "08/15"
stopifnot(length(metadata(copy)) == length(metadata(vaas_1)))
stopifnot(metadata(copy, "Strain") != metadata(vaas_1, "Strain"))

# WMD/factor/any method
metadata(copy, as.factor("Strain")) <- metadata(vaas_1, "Strain")
stopifnot(metadata(copy, "Strain") == metadata(vaas_1, "Strain"))

## WMDS methods

# WMDS/missing/list method
copy <- vaas_4
(metadata(copy) <- list(x = -99)) # will replace all of them
## $x
## [1] -99
stopifnot(identical(unique(metadata(copy)), list(list(x = -99))))
metadata(copy[2]) <- list(x = 1) # will replace those of 2nd plate
stopifnot(identical(unique(metadata(copy)),
  list(list(x = -99), list(x = 1))))

# WMDS/missing/WMD method
(metadata(copy) <- vaas_1) # will also replace all of them
## Class                 OPMD
## From file             ./E. coli DSM
##                       30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
##                       7B_5.csv
## Hours measured        95.75
## Number of wells       96
## Plate type            Gen III
## Position              7-B
## Setup time            8/30/2010 1:53:08 PM
## Metadata              5
## Aggregated            TRUE
## Discretized           TRUE
stopifnot(identical(unique(metadata(copy)), list(metadata(vaas_1))))

# WMDS/missing/formula method
copy <- vaas_4
metadata(copy) <- Organism ~ paste(Species, Strain)
(x <- metadata(copy, "Organism"))
## [1] "Escherichia coli DSM18039"      "Escherichia coli DSM30083T"    
## [3] "Pseudomonas aeruginosa DSM1707" "Pseudomonas aeruginosa 429SC1"
stopifnot(length(x) == length(metadata(vaas_4, "Organism")) + 4)

# WMDS/ANY/ANY method
copy <- vaas_4
(metadata(copy, "Species") <- "Bacillus subtilis") # will set all of them
## [1] "Bacillus subtilis"
stopifnot(identical(unique(metadata(copy, "Species")), "Bacillus subtilis"))
stopifnot(!identical(metadata(copy), metadata(vaas_4)))
metadata(copy) <- vaas_4 # reset
metadata(copy)
## [[1]]
## [[1]]$Experiment
## [1] "First replicate"
## 
## [[1]]$Species
## [1] "Escherichia coli"
## 
## [[1]]$Strain
## [1] "DSM18039"
## 
## [[1]]$Slot
## [1] "B"
## 
## [[1]]$`Plate number`
## [1] 6
## 
## 
## [[2]]
## [[2]]$Experiment
## [1] "First replicate"
## 
## [[2]]$Species
## [1] "Escherichia coli"
## 
## [[2]]$Strain
## [1] "DSM30083T"
## 
## [[2]]$Slot
## [1] "B"
## 
## [[2]]$`Plate number`
## [1] 6
## 
## 
## [[3]]
## [[3]]$Experiment
## [1] "First replicate"
## 
## [[3]]$Species
## [1] "Pseudomonas aeruginosa"
## 
## [[3]]$Strain
## [1] "DSM1707"
## 
## [[3]]$Slot
## [1] "B"
## 
## [[3]]$`Plate number`
## [1] 6
## 
## 
## [[4]]
## [[4]]$Experiment
## [1] "First replicate"
## 
## [[4]]$Species
## [1] "Pseudomonas aeruginosa"
## 
## [[4]]$Strain
## [1] "429SC1"
## 
## [[4]]$Slot
## [1] "B"
## 
## [[4]]$`Plate number`
## [1] 6
stopifnot(identical(metadata(copy), metadata(vaas_4)))
(metadata(copy) <- vaas_1) # set everything to metadata of vaas_1
## Class                 OPMD
## From file             ./E. coli DSM
##                       30083T_vim10_7B__1_28_PMX_0_8#30#2010_F_
##                       7B_5.csv
## Hours measured        95.75
## Number of wells       96
## Plate type            Gen III
## Position              7-B
## Setup time            8/30/2010 1:53:08 PM
## Metadata              5
## Aggregated            TRUE
## Discretized           TRUE
stopifnot(identical(unique(metadata(copy)), list(metadata(vaas_1))))

# WMDS/character/data frame method
copy <- vaas_4
(x <- data.frame(Type = grepl("T$", metadata(vaas_4, "Strain"))))
##    Type
## 1 FALSE
## 2  TRUE
## 3 FALSE
## 4 FALSE
metadata(copy, "Type") <- x
# one-column data frames are simplified
stopifnot(identical(metadata(copy, "Type"), x$Type))
# if keys match, a partial selection of the data frame is used
(x <- cbind(x, Notype = !x$Type))
##    Type Notype
## 1 FALSE   TRUE
## 2  TRUE  FALSE
## 3 FALSE   TRUE
## 4 FALSE   TRUE
metadata(copy, "Type") <- x
stopifnot(identical(metadata(copy, "Type"), x$Type))
# if keys do not match, the entire data-frame rows are included
metadata(copy, "Type2") <- x
stopifnot(!identical(metadata(copy, "Type2"), x$Type))

# WMDS/missing/character method: setting unique IDs
metadata(copy) <- opm_opt("md.id.name") # set IDs
metadata(copy, opm_opt("md.id.name")) # get these IDs
## [1] 5 6 7 8
stopifnot(is.integer(metadata(copy, opm_opt("md.id.name"))))
# to reset the start point to the number n, use opm_opt(md.id.start = n)

# WMDS/missing/character method: setting the running time
metadata(copy) <- opm_opt("md.duration") # set it
metadata(copy, opm_opt("md.duration")) # receive it
## [1] 95.75 95.75 95.75 95.75
stopifnot(is.double(metadata(copy, opm_opt("md.duration"))))

# WMDS/missing/logical method: storing or deleting csv_data() entries
copy <- vaas_4
metadata(copy) <- TRUE # store them
stopifnot(ncol(to_metadata(copy)) > ncol(to_metadata(vaas_4)))
metadata(copy) <- FALSE # remove them again
stopifnot(identical(metadata(copy), metadata(vaas_4)))

[Package opm version 1.3.63 Index]