Skip to contents

# Compacting a vector of any length with or without names

Source: `R/ds2dd_detailed.R`
`compact_vec.Rd`

Compacting a vector of any length with or without names

## Usage

    compact_vec(data, nm.sep = ": ", val.sep = "; ")

## Arguments

data

  vector, optionally named

nm.sep

  string separating name from value if any

val.sep

  string separating values

## Value

character string

## Examples

    sample(seq_len(4), 20, TRUE) |>
      as_factor() |>
      named_levels() |>
      sort() |>
      compact_vec()
    #> [1] "1: 1; 2: 2; 3: 3; 4: 4"
    1:6 |> compact_vec()
    #> [1] "1; 2; 3; 4; 5; 6"
    "test" |> compact_vec()
    #> [1] "test"
    sample(letters[1:9], 20, TRUE) |> compact_vec()
    #> [1] "i; e; c; b; g; d; d; b; i; b; c; c; a; g; e; d; a; c; g; a"