Learn R Programming

bolt4jr (version 1.4.0)

convert_df: Convert a Query Result into a Data Frame

Description

This function takes a query result object and transforms it into a data frame with specified field names. For each entry in the query result, it attempts to extract values corresponding to the given field names. If a particular field does not exist in the entry, it is replaced with NA.

Usage

convert_df(
  query_result,
  field_names = c("node_id", "n.identifier", "n.name", "n.source")
)

Value

A data frame with one row per entry in query_result, and columns corresponding to the specified field_names. Missing fields are filled with NA.

Arguments

query_result

A list (or similar structure) representing the query result, typically containing entries from which fields can be extracted.

field_names

A character vector of field names to be extracted from each entry in query_result. Defaults to c("node_id", "n_identifier", "n.name", "n.source").

Examples

Run this code
# \donttest{
# Suppose query_result is a list of named lists:
query_result = list(
  list(node_id = 1, n = list(identifier = 1, name = "some node", source = "internet")),
  list(node_id = 2, n = list(identifier = 2, name = "some other node", source = "library"))
)

query_result_df = convert_df(
  query_result,
  field_names = c("node_id", "n.identifier", "n.name", "n.source")
)
# }

Run the code above in your browser using DataLab