aggregate_values_by_key: Aggregates matrices values based on specified key.

Description Usage Arguments Details Value See Also Examples

View source: R/aggregate-functions.R

Description

\lifecycle

experimental Performs aggregation on values contained in the integration matrices based on the key and the specified lambda. For more details on how to use this function: vignette("Working with aggregate functions", package = "ISAnalytics")

Usage

1
2
3
4
5
6
7
8
aggregate_values_by_key(
  x,
  association_file,
  value_cols = "Value",
  key = c("SubjectID", "CellMarker", "Tissue", "TimePoint"),
  lambda = list(sum = ~sum(.x, na.rm = TRUE)),
  group = c(mandatory_IS_vars(), annotation_IS_vars())
)

Arguments

x

A single integration matrix (tibble) or a list of imported integration matrices (tibble)

association_file

The imported association file

value_cols

A character vector containing the names of the columns to apply the given lambdas. Must be numeric or integer columns.

key

A string or a character vector with column names of the association file to take as key

lambda

A named list of functions or purrr-style lambdas. See details section.

group

Other variables to include in the grouping besides key, can be set to NULL

Details

Setting the lambda parameter

The lambda parameter should always contain a named list of either functions or purrr-style lambdas. It is also possible to specify the namespace of the function in both ways, for example:

lambda = list(sum = sum, desc = psych::describe)

Using purrr-style lambdas allows to specify arguments for the functions, keeping in mind that the first parameter should always be .x:

lambda = list(sum = ~sum(.x, na.rm = TRUE))

It is also possible to use custom user-defined functions, keeping in mind that the symbol will be evaluated in the calling environment, for example if the function is called in the global environment and lambda contains "foo" as a function, "foo" will be evaluated in the global environment.

foo <- function(x) {
  sum(x)
}

lambda = list(sum = ~sum(.x, na.rm = TRUE), foo = foo)

# Or with lambda notation
lambda = list(sum = ~sum(.x, na.rm = TRUE), foo = ~foo(.x))

Constraints on aggregation functions

Functions passed in the lambda parameters must respect a few constraints to properly work and it's the user responsibility to ensure this.

Value

A list of tibbles or a single tibble according to input

See Also

Other Aggregate functions: aggregate_metadata()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
op <- options("ISAnalytics.widgets" = FALSE, "ISAnalytics.verbose" = FALSE)
path_AF <- system.file("extdata", "ex_association_file.tsv",
    package = "ISAnalytics"
)
root_correct <- system.file("extdata", "fs.zip", package = "ISAnalytics")
root_correct <- unzip_file_system(root_correct, "fs")
association_file <- import_association_file(path_AF, root_correct,
    dates_format = "dmy"
)
matrices <- import_parallel_Vispa2Matrices_auto(
    association_file = association_file, root = NULL,
    quantification_type = c("fragmentEstimate", "seqCount"),
    matrix_type = "annotated", workers = 2, matching_opt = "ANY"
)
agg <- aggregate_values_by_key(
    x = matrices,
    association_file = association_file,
    value_cols = c("fragmentEstimate", "seqCount")
)
options(op)

ISAnalytics documentation built on April 9, 2021, 6:01 p.m.