Create data frame of specified fields from database collection
Source:R/utils.R
dbGetFieldsIntoDf.Rd
Fields in the collection are retrieved into a data frame (or tibble). Note that fields within the record of a trial can be hierarchical and structured, that is, nested. Names of fields can be found with dbFindFields. The function uses the field names to appropriately type the values that it returns, harmonising original values (e.g. "Information not present in EudraCT" becomes `NA`, "Yes" becomes `TRUE`, "false" becomes `FALSE`, date strings become class Date, number strings become numbers). The function attempts so simplify the structure of some nested data and may concatenate multiple strings in a field using " / " (see below); for complex nested data, use function dfTrials2Long followed by dfName2Value to extract the desired nested variable(s).
Arguments
- fields
Vector of one or more strings, with names of sought fields. See function dbFindFields for how to find names of fields. "item.subitem" notation is supported.
- con
A connection object, see section `Databases` in ctrdata-package
- verbose
Printing additional information if set to
TRUE
; (defaultFALSE
).- stopifnodata
Stops with an error (detaul
TRUE
) or with a warning (FALSE
) if the sought field is empty in all, or not available in any of the records in the database collection.
Value
A data frame (or tibble, if dplyr
is loaded)
with columns corresponding to the sought fields.
A column for the record `_id` will always be included.
Each column can be either a simple data type (numeric, character, date)
or a list. For complicated lists, use function
dfTrials2Long followed by function dfName2Value to
extract values for nested variables.
The maximum number of rows of the returned data frame is equal to,
or less than the number of records of trials in the database
collection.
Examples
dbc <- nodbi::src_sqlite(
dbname = system.file("extdata", "demo.sqlite", package = "ctrdata"),
collection = "my_trials")
# 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)
#> b1_sponsor.b31_and_b32_status_of_the_sponsor...
#>
#> .
#> _id b1_sponsor.b31_and_b32_status_of_the_sponsor
#> 110 2012-003632-23-AT Commercial
#> 210 2012-003632-23-CZ Commercial
#> 3 2012-003632-23-DE Commercial
#> 4 2012-003632-23-ES Commercial
#> 5 2012-003632-23-GB Commercial
#> 6 2012-003632-23-IT Commercial
#> 7 2012-003632-23-SE Commercial
#> 8 2013-005512-10-DE Commercial
#> 9 2013-005512-10-DK Commercial
#> 10 2013-005512-10-ES Commercial
#> 11 2013-005512-10-FR Commercial
#> 12 2013-005512-10-GB Commercial
#> 13 2013-005512-10-IE Commercial
#> 14 2013-005512-10-IT Commercial
#> 15 2013-005512-10-NL Commercial
#> 16 2013-005512-10-PL Commercial
#> 17 2013-005512-10-SE Commercial
#> 18 2014-002606-20-3RD Commercial
#> 19 2014-002606-20-AT Commercial
#> 20 2014-002606-20-DE Commercial
#> 21 2014-002606-20-ES Commercial
#> 22 2014-002606-20-GB Commercial
#> 23 2014-002606-20-IT Commercial
#> 24 2014-002606-20-PT Commercial
#> 25 2014-003556-31-GB Commercial
#> 26 2014-003556-31-IT Commercial
#> 27 2014-003556-31-NL Commercial
#> 28 2014-003556-31-PL Commercial
#> 29 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)
#> keyword...
#>
#> _id
#> 110 NCT01035190
#> 210 NCT01190995
#> 38 NCT01265589
#> 41 NCT01389856
#> 51 NCT01490580
#> 61 NCT01517828
#> 72 NCT01528852
#> 81 NCT01536483
#> 101 NCT01720524
#> 111 NCT01723501
#> 121 NCT01783041
#> 131 NCT01875757
#> 141 NCT01899677
#> 151 NCT01954082
#> 161 NCT02056223
#> 171 NCT02374281
#> 181 NCT02499393
#> 231 NCT03022253
#> 241 NCT03058666
#> 261 NCT03082001
#> 331 NCT03272594
#> keyword
#> 110 Preterm Infants / Inhaled Corticosteroids / Bronchopulmonary Dysplasia
#> 210 Pain / Neonate / Procedure / Neurobehavioural outcome
#> 38 RDS / Infant, newborn / Vitamin A / Surfactant
#> 41 Persistent pulmonary hypertension, newborn / PPHN
#> 51 Pain / Newborn / Anaesthesia / opioids / propofol / neuromuscular blocker / atropine
#> 61 Intubation / Delivery room / Sedation / Analgesia
#> 72 neonatal Mortality / chlorhexidine cord care / cord infections / african settings / clinical trials
#> 81 Butyrate / Preterms / Very Low Birth Weight (<1250g) / Rectocolonic enemas / Digestive maturation / Parenteral nutrition weaning / ECUN / Whole gut transit time
#> 101 persistent pulmonary hypertension / newborn / neonates / iv sildenafil / hypoxic respiratory failure and at risk of persistent pulmonary hypertension of the newborn
#> 111 chlorhexidine / sepsis / neonatal / whole-body skin cleansing
#> 121 Prematurity / Carnitine supplementation / Neonatal Intensive Care / MRI / Amplitude-integrated EEG / NICU Network Neurobehavioral Scale / Bayley Scale of Infant Development III
#> 131 Vitamin D / Acute bronchitis / Upper respiratory tract infection / Recurrent bronchitis / Acute bronchiolitis / Infants
#> 141 Symbiotic,cytokines, necrotising enterocolitis
#> 151 Retinopathy / Prematurity / Infant, Newborn, Diseases
#> 161 Patent ductus arteriosus / Preterm infant / Paracetamol / Ibuprofen
#> 171 Newborn / Neonatal Screening / Autonomic Nervous System / Pain / non-nutritive sucking / sucrose administration / nociceptive action / Electro acoustical characteristics of crying
#> 181 newborn / therapeutic hypothermia / magnesium sulphate
#> 231 PDA / Platelets
#> 241 Aerosol / surfactant / calfactant / Infasurf / Respiratory Distress Syndrome / RDS / Premature / Neonates
#> 261 Neonate / Pain / ELBW
#> 331 Neonatal pain / Pediatric pain / Pain assessment / Breastfeeding / Sucrose / Randomized controlled trial / Behavioural pain response / Neurophysiological pain response