Skip to contents

Add sample names

Usage

qp_add_names(x, ...)

# S3 method for list
qp_add_names(x, sample_names = NULL, ...)

# S3 method for data.frame
qp_add_names(x, sample_names = NULL, ...)

Arguments

x

A data.frame (or a list containing one) that contains columns index (which denotes sample number) and sample_type, which should be either "unknown" or "standard".

...

Unused

sample_names

Optional character vector. If NULL, uses sample index. In a standard workflow, the index is the order the sample appears in the plate

Examples


df <- expand.grid(
  index = c(1, 1, 2, 2, 2, 3),
  sample_type = c("standard", "unknown")
)

df
#>    index sample_type
#> 1      1    standard
#> 2      1    standard
#> 3      2    standard
#> 4      2    standard
#> 5      2    standard
#> 6      3    standard
#> 7      1     unknown
#> 8      1     unknown
#> 9      2     unknown
#> 10     2     unknown
#> 11     2     unknown
#> 12     3     unknown

# You don't get to name standards:
qp_add_names(df, c("a", "b", "c"))
#>    index sample_type .sample_name
#> 1      1    standard   Standard 1
#> 2      1    standard   Standard 1
#> 3      2    standard   Standard 2
#> 4      2    standard   Standard 2
#> 5      2    standard   Standard 2
#> 6      3    standard   Standard 3
#> 7      1     unknown            a
#> 8      1     unknown            a
#> 9      2     unknown            b
#> 10     2     unknown            b
#> 11     2     unknown            b
#> 12     3     unknown            c

# If there aren't enough names, will use index
qp_add_names(df, c("a", "b"))
#>    index sample_type .sample_name
#> 1      1    standard   Standard 1
#> 2      1    standard   Standard 1
#> 3      2    standard   Standard 2
#> 4      2    standard   Standard 2
#> 5      2    standard   Standard 2
#> 6      3    standard   Standard 3
#> 7      1     unknown            a
#> 8      1     unknown            a
#> 9      2     unknown            b
#> 10     2     unknown            b
#> 11     2     unknown            b
#> 12     3     unknown            3

# No names provided will use index by default
qp_add_names(df)
#>    index sample_type .sample_name
#> 1      1    standard   Standard 1
#> 2      1    standard   Standard 1
#> 3      2    standard   Standard 2
#> 4      2    standard   Standard 2
#> 5      2    standard   Standard 2
#> 6      3    standard   Standard 3
#> 7      1     unknown            1
#> 8      1     unknown            1
#> 9      2     unknown            2
#> 10     2     unknown            2
#> 11     2     unknown            2
#> 12     3     unknown            3