list_records_to_df: Convert a list of records to a data.frame

View source: R/list_records_to_df.R

list_records_to_dfR Documentation

Convert a list of records to a data.frame

Description

Converts a list where each element represents a record (row) into a data.frame. Missing fields are filled with NA.

Usage

list_records_to_df(x)

Arguments

x

A list of records. Each record should be a named list or similar structure. Records may have different sets of fields.

Details

List-valued fields are flattened by collapsing their contents into a single character value. This guarantees that the returned data frame contains no list columns, but nested structure is not preserved.

This function is intended for row-oriented data structures, such as JSON arrays of objects.

Value

A data.frame with one row per record and columns corresponding to the union of all field names.

Note

This function is written and documented with help from ChatGPT.

Examples

x <- list(
  list(id = 1, name = "Ada", tags = list("a", "b")),
  list(id = 2, name = "Bo"),
  list(id = 3, name = "Cy", tags = list("x"))
)

list_records_to_df(x)


PxWebApiData documentation built on Sept. 9, 2026, 5:07 p.m.