Skip to contents

Fields in the collection are retrieved from all records into a data frame (or tibble). Within a given trial record, a fields can be hierarchical and structured, that is, nested. Th function uses the field names to appropriately type the values that it returns, harmonising original values (e.g. "Information not present in EudraCT" to `NA`, "Yes" to `TRUE`, "false" to `FALSE`, date strings to dates or time differences, number strings to numbers). The function simplifies the structure of nested data and may concatenate multiple strings in a field using " / " (see example) and may have widened the returned data frame with additional columns that were recursively expanded from simply nested data (e.g., "externalRefs" to columns "externalRefs.doi", "externalRefs.eudraCTNumber" etc.). For an alternative way for handling the complex nested data, see dfTrials2Long followed by dfName2Value for extracting the sought variable(s).

Usage

dbGetFieldsIntoDf(fields = "", con, verbose = FALSE, ...)

Arguments

fields

Vector of one or more strings, with names of sought fields. See function dbFindFields for how to find names of fields. Dot path notation ("field.subfield") without indices is supported. If compatibility with `nodbi::src_postgres()` is needed, specify fewer than 50 fields, consider also using parent fields e.g., `"a.b"` instead of `c("a.b.c.d", "a.b.c.e")`, accessing sought fields with dfTrials2Long followed by dfName2Value or other R functions.

con

A connection object, see section `Databases` in ctrdata.

verbose

Printing additional information if set to TRUE; (default FALSE).

...

Do not use (captures deprecated parameter stopifnodata)

Value

A data frame (or tibble, if tibble is loaded) with columns corresponding to the sought fields. A column for the records' `_id` will always be included. The maximum number of rows of the returned data frame is equal to, or less than the number of trial records in the database collection.

Examples


dbc <- nodbi::src_sqlite(
   dbname = system.file("extdata", "demo.sqlite", package = "ctrdata"),
   collection = "my_trials")
#> RSQLite version has enabled accelerating docdb_create() and docdb_update() functions when used with value = <NDJSON file name>.

# get fields that are nested within another field
# and can have multiple values with the nested field
dbGetFieldsIntoDf(
  fields = "b1_sponsor.b31_and_b32_status_of_the_sponsor",
  con = dbc)
#>                 _id b1_sponsor.b31_and_b32_status_of_the_sponsor
#> 1 2012-003632-23-CZ                                   Commercial
#> 2 2012-003632-23-SE                                   Commercial
#> 5 2014-002606-20-PT                                   Commercial
#> 4 2014-003556-31-GB                                   Commercial
#> 3 2014-003556-31-SE                                   Commercial

# fields that are lists of string values are
# returned by concatenating values with a slash
dbGetFieldsIntoDf(
  fields = "keyword",
  con = dbc)
#>           _id
#> 2 NCT03280147
#> 3 NCT03325439
#> 4 NCT03431558
#> 6 NCT04001712
#> 7 NCT04041765
#>                                                                                                  keyword
#> 2                                                              Neonate / Sepsis / Antibiotics / Duration
#> 3 Electroencephalographic neonatal seizures / Brivaracetam / Epilepsy / ENS / Newborns / Pharmacokinetic
#> 4                                               Bovine Lactoferrin, Neonatal infection, Low Birth Weight
#> 6                                                                                 early caffeine preterm
#> 7                                                                IgM-enriched Intravenous Immunoglobulin