capture_longer_spec {nc}R Documentation

capture longer spec

Description

Create a spec data table for input to pivot_longer_spec.

Usage

capture_longer_spec(data, 
    ..., values_to = "value")

Arguments

data

Data table to reshape (actually the data are ignored, and only the column names are used).

...

Regex and conversion as described in capture_first_vec. This is processed by measure so if "column" is used as an argument name then there will be multiple output columns in the reshaped data (analogous to names_to=".value" in pivot_longer).

values_to

string to use for name of value column in output (only used if there is a single output column in the reshaped data).

Value

data table describing a reshape longer operation.

Author(s)

Toby Hocking <toby.hocking@r-project.org> [aut, cre]

Examples


(one.iris <- iris[1,])
(single.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", dim=".*", values_to="cm"))
(multiple.spec <- nc::capture_longer_spec(iris, part=".*", "[.]", column=".*"))
if(requireNamespace("tidyr")){
  tidyr::pivot_longer_spec(one.iris, single.spec)
  tidyr::pivot_longer_spec(one.iris, multiple.spec)
}


[Package nc version 2024.2.21 Index]