metadata.set {opm} | R Documentation |
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.
## 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
object |
|
key |
Missing, numeric scalar, character vector, factor, or list.
|
value |
Character vector, list, data frame, formula,
|
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
.
Other metadata-functions: edit
,
include_metadata
,
map_metadata
, map_values
,
metadata
, metadata_chars
## 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)))