sort: Sort, unify, revert or repeat OPMS objects

Description Usage Arguments Details Value See Also Examples

Description

Sort an OPMS object based on one to several metadata or CSV data entries, or sort elements of a MOPMX object based on plate type, length, or a metadata entry. Alternatively, remove duplicated elements from a OPMS or MOPMX object, or revert the order of plates within an OPMS object, or, repeat OPMS or OPM objects zero times, once, or several times.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  ## S4 method for signature 'OPM'
rep(x, ...) 
  ## S4 method for signature 'OPMS'
rep(x, ...) 

  ## S4 method for signature 'OPM'
rev(x) 
  ## S4 method for signature 'OPMS'
rev(x) 

  ## S4 method for signature 'MOPMX,ANY'
sort(x, decreasing,
    by = c("plate.type", "length"), exact = TRUE, strict = TRUE,
    na.last = TRUE, ...) 
  ## S4 method for signature 'MOPMX,missing'
sort(x, decreasing, ...) 
  ## S4 method for signature 'OPM,ANY'
sort(x, decreasing, ...) 
  ## S4 method for signature 'OPM,missing'
sort(x, decreasing, ...) 
  ## S4 method for signature 'OPMS,ANY'
sort(x, decreasing, by = "setup_time",
    parse = identical(by, "setup_time"), exact = TRUE, strict = TRUE,
    na.last = TRUE) 
  ## S4 method for signature 'OPMS,missing'
sort(x, decreasing, ...) 

  ## S4 method for signature 'MOPMX,ANY'
unique(x, incomparables, ...) 
  ## S4 method for signature 'MOPMX,missing'
unique(x, incomparables, ...) 
  ## S4 method for signature 'OPM,ANY'
unique(x, incomparables, ...) 
  ## S4 method for signature 'OPM,missing'
unique(x, incomparables, ...) 
  ## S4 method for signature 'OPMS,ANY'
unique(x, incomparables, ...) 
  ## S4 method for signature 'OPMS,missing'
unique(x, incomparables, ...) 

Arguments

x

OPM or OPMS or MOPMX object.

decreasing

Logical scalar. Passed to order or sort.list from the base package.

by

List or character vector. For OPMS objects, if a list, a list of one to several keys passed as key argument to metadata. If a character vector of length one, by is passed as ‘what’ argument to csv_data. If longer, passed step-by-step to csv_data as keys argument. When identical to ‘hours’, by triggers sorting according to the overall measurement time.

For MOPMX objects, either ‘plate.type’, which sorts according to the plate types, ‘length’, which sorts the elements according to their lengths (i.e., number of plates), or a metadata query that yields, for each element of x, a vector to which max can be applied. Sorting x is then done according to these maxima.

parse

Logical scalar. Convert the setup_time via strptime before ordering? Has only an effect if by is ‘setup_time’. It is an error if the time format is not recognised. See opm_opt, arguments time.fmt and time.zone, for modifying the parsing of setup-time entries, and csv_data for this kind of entries.

exact

Logical scalar. Passed to metadata. Affects only metadata querying, not directly the sorting.

strict

Logical scalar. Is it an error if metadata keys are not found? If FALSE, x gets ordered according to only the found keys, and remains in the original order if none of the keys in by are found at all. Note that it is always an error if keys are found in the metadata of some of the plates but not in those of others.

na.last

Logical scalar. Also passed to order or sort.list.

incomparables

Vector passed to duplicated. The default is FALSE.

...

Optional arguments passed between the methods or to duplicated or to rep from the base package. See the examples.

Details

The sort OPM method just returns the input data to avoid destructive effects due to the way the default sort interacts with OPM indexing.

rev should be slightly more efficient than calling the default rev method. There is also an OPM method which just returns the input data (to avoid destructive effects due to the way the default rev interacts with OPM indexing).

The OPM method of unique also returns the passed object.

rev yields an OPMS object with another number of plates, or an OPM object, or NULL.

Value

OPMS object with not necessarily the same order of plates than before, or OPM object.

See Also

base::order base::sort base::strptime base::unique base::rev

base::rep

Other conversion-functions: as.data.frame, extract, extract_columns, flatten, merge, oapply, opmx, plates, split, to_yaml

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
## 'OPMS' methods

# Existing keys
stopifnot(is.unsorted(metadata(vaas_4, "Strain")))
x <- sort(vaas_4, by = list("Strain"))
stopifnot(is(x, "OPMS"), !is.unsorted(metadata(x, "Strain")))
x <- sort(vaas_4, by = list("Strain"), decreasing = TRUE)
stopifnot(is(x, "OPMS"), is.unsorted(metadata(x, "Strain")))

# Non-existing keys
x <- try(sort(vaas_4, by = list("Not there", "Missing"), strict = TRUE))
stopifnot(inherits(x, "try-error")) # yields error
x <- try(sort(vaas_4, by = list("Not there", "Missing"), strict = FALSE))
stopifnot(identical(x, vaas_4)) # no error, but no new order

# CSV-data based
copy <- sort(vaas_4) # default: by setup time
csv_data(vaas_4, what = "setup_time")
csv_data(copy, what = "setup_time")
stopifnot(!identical(copy, vaas_4))
copy <- sort(vaas_4, by = c("Position", "Setup Time"))
csv_data(vaas_4, what = "position")
csv_data(copy, what = "position")
stopifnot(!is.unsorted(csv_data(copy, what = "position")))
stopifnot(is.unsorted(csv_data(vaas_4, what = "position")))

# sorting accoring to overall measurement duration
stopifnot(identical(sort(vaas_4, TRUE, "hours"), vaas_4))
# (uniform measurements durations in this object)

# making OPMS objects unique
dim(x <- unique(vaas_4))
stopifnot(identical(x, vaas_4))
dim(x <- unique(c(vaas_4, vaas_4)))
stopifnot(identical(x, vaas_4))
dim(x <- unique(vaas_4, what = "Species")) # species are not unique
stopifnot(dim(x)[1L] < dim(vaas_4)[1L])
dim(x <- unique(vaas_4, what = list("Species", "Strain")))
stopifnot(identical(x, vaas_4)) # organisms are unique

# reverting an OPMS object
dim(x <- rev(vaas_4))
stopifnot(dim(x) == dim(vaas_4), !identical(x, vaas_4))
stopifnot(identical(rev(x), vaas_4))

# repeating an OPMS object
dim(x <- rep(vaas_4))
stopifnot(identical(x, vaas_4))
dim(x <- rep(vaas_4, times = 2))
stopifnot(length(x) == length(vaas_4) * 2)
dim(y <- rep(vaas_4, each = 2))
stopifnot(length(y) == length(vaas_4) * 2, !identical(x, y))
stopifnot(is.null(rep(vaas_4, 0)))

## 'OPM' methods
summary(x <- sort(vaas_1))
stopifnot(identical(x, vaas_1))
dim(x <- unique(vaas_1)) # trivial
stopifnot(identical(x, vaas_1))
dim(x <- unique(vaas_1, what = list("Species", "Strain")))
stopifnot(identical(x, vaas_1))
dim(x <- rev(vaas_1)) # trivial
stopifnot(identical(x, vaas_1))
dim(x <- rep(vaas_1, 1))
stopifnot(identical(x, vaas_1))
dim(x <- rep(vaas_1, 2)) # conversion to OPMS if > 1 element
stopifnot(length(x) == 2, is(x, "OPMS"))
stopifnot(is.null(rep(vaas_4, 0)))

opm documentation built on May 2, 2019, 6:08 p.m.