wide_pivot_first: Fast long-to-wide pivot taking the first value per id/name...

View source: R/get_cheminfo.R

wide_pivot_firstR Documentation

Fast long-to-wide pivot taking the first value per id/name pair

Description

Internal helper used by get_cheminfo to replace tidyr::pivot_wider(..., values_fn = dplyr::first, values_fill = NA) with a much faster matrix-based implementation. tidyr's pivot_wider incurs substantial overhead from its generic duplicate-handling/values_fn machinery, which dominates runtime on httk's larger chemprop table (~167k rows); this function gives an identical result (one row per distinct id, one column per distinct name, first value kept for duplicated id/name pairs, NA for missing combinations) much faster.

Usage

wide_pivot_first(data, id_col, name_col, value_col)

Arguments

data

A long-format data frame with id, name, and value columns.

id_col

Name of the column identifying each output row.

name_col

Name of the column whose distinct values become output column names.

value_col

Name of the column supplying output cell values.

Value

A data frame with one row per distinct value of id_col and one column per distinct value of name_col.


httk documentation built on Nov. 26, 2026, 9:08 a.m.