MetadataActionTranslate: Metadata action: translate

MetadataActionTranslateR Documentation

Metadata action: translate

Description

Metadata action: translate

Metadata action: translate

Details

Performs a dictionary-style translation action for an entry. In the reading direction, multiple entries may be mapped to one output value; in the writing direction, a single value needs to be specified. If coalesce is set, untranslated values will be copied verbatim.

Super class

SpectraMapping::MetadataActionBase -> MetadataActionTranslate

Methods

Public methods

Inherited methods

Method process_read()

read implementation

Usage
MetadataActionTranslate$process_read(data, params)
Arguments
data

MsBackendMapping to execute the metadata mapping step on

params

List of parameters for a single action (one params entry fully merged.)


Method process_write()

write implementation

Usage
MetadataActionTranslate$process_write(data, params)
Arguments
data

MsBackendMapping to execute the metadata mapping step on

params

List of parameters for a single action (one params entry fully merged.)


Method clone()

The objects of this class are cloneable with this method.

Usage
MetadataActionTranslate$clone(deep = FALSE)
Arguments
deep

Whether to make a deep clone.

Examples


backend <- get_proto_backend(MS_TYPE = c("POSITIVE", "P", "n", "gugus", NA))
action <- get_proto_action(
   "translate",
   source = "MS_TYPE",
   target = "*msLevel",
   dictionary = list(
   list(value = 1, read = c("POSITIVE", "P", "p", "pos"), write = "POSITIVE"),
   list(value = 0, read = c("NEGATIVE", "N", "n", "neg"), write = "NEGATIVE")
   )
)
fw <- action$execute_read(backend)
fw@variables <- fw@variables %>% select(-MS_TYPE)

# Example with `coalesce`: 
# Note that `coalesce` only works when source and destination type are equal.

backend <- get_proto_backend(MS_TYPE = c("POSITIVE", "P", "n", "gugus", NA))
action <- get_proto_action(
   "translate",
   source = "MS_TYPE",
   target = "*msLevel",
   coalesce = TRUE,
   dictionary = list(
   list(value = "1", read = c("POSITIVE", "P", "p", "pos"), write = "POSITIVE"),
   list(value = "0", read = c("NEGATIVE", "N", "n", "neg"), write = "NEGATIVE")
   )
)

fw <- action$execute_read(backend)
fw@variables <- fw@variables %>% select(-MS_TYPE)
bw <- action$execute_write(fw)


meowcat/SpectraMapping documentation built on May 14, 2024, 6:30 p.m.