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

View source: R/utils.R

dfListExtractKeyR Documentation

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

Description

(Deprecated, use dfTrials2Long and dfName2Value!) 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 (or tibble)

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 (or tibble, if dplyr is loaded) 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


dbc <- nodbi::src_sqlite(
   dbname = system.file("extdata", "demo.sqlite", package = "ctrdata"),
   collection = "my_trials")

df <- dbGetFieldsIntoDf(
  fields = c(
    "endPoints.endPoint",
    "subjectDisposition.postAssignmentPeriods"),
  con = dbc)

suppressWarnings(
  dfListExtractKey(
    df = df,
    list.key = list(
        c("endPoints.endPoint",
          "^title"),
        c("subjectDisposition.postAssignmentPeriods",
          "arms.arm.type.value"))
))


ctrdata documentation built on Nov. 21, 2022, 1:06 a.m.