Skip to contents

Add leading 0 to sample names

Usage

pad_zero(sample_names)

Arguments

sample_names

a vector of sample names

Value

A sample name with up to one zero padded

Examples

c("blueberry", "Sample 1", "Sample 10", "sample 2", "john", "larry", "toxic waste", "Sample 02") |>
  pad_zero()
#> [1] "blueberry"   "Sample 01"   "Sample 10"   "sample 2"    "john"       
#> [6] "larry"       "toxic waste" "Sample 02"  

# pad_zero will not pad if it doesn't need to:
c("Sample 1", "Sample 2", "Sample 9") |> pad_zero()
#> [1] "Sample 1" "Sample 2" "Sample 9"

# pad_zero is case sensitive, since these will be coming off a machine in a standardized format

c("sample 10", "sample 1") |> pad_zero()
#> [1] "sample 10" "sample 1" 
c("Sample 10", "Sample 1") |> pad_zero()
#> [1] "Sample 10" "Sample 01"