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

Description Usage Arguments Value Examples

View source: R/utils.R

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

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
## 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")
))

## End(Not run)

ctrdata documentation built on Nov. 22, 2021, 1:06 a.m.