Learn R Programming

ctrdata (version 1.5.2)

dfListExtractKey: Extract named element(s) from list(s) into long-format data frame

Description

The function uses a name (key) to extract an element from a list in a data.frame such as obtained with dbGetFieldsIntoDf. This helps to simplify working with nested lists and with complex structures.

Usage

dfListExtractKey(df, list.key = list(c("endPoints.endPoint", "^title")))

Arguments

df

A data frame

list.key

A list of pairs of list names and key names, where the list name corresponds to the name of a column in df that holds a list and the name of the key identifies the element to be extracted. See example.

Value

A data frame in long format with columns name (identifying the full path in the data frame, "<list>.<key>"), _id (of the trial record), value (of name per _id), item (number of value of name per _id).

Examples

Run this code
# NOT RUN {
# }
# NOT RUN {
db <- nodbi::src_sqlite(
  collection = "my_collection"
)
df <- dbGetFieldsIntoDf(
  fields = c(
    "endPoints.endPoint",
    "subjectDisposition.postAssignmentPeriods"),
  con = db
)
dfListExtractKey(
  df = df,
  list.key = list(
      c("endPoints.endPoint",
        "^title"),
      c("subjectDisposition.postAssignmentPeriods",
        "arms.arm.type.value")
))
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab