Last chance! 50% off unlimited learning
Sale ends in
With this convenience function, fields in the mongo database are retrieved into an R dataframe. As mongo json fields within the record of a trial can be hierarchical and structured, the function flattens the data and returns a concatenation of values if there is more than one value or if the field is (in) an array, such as follows: value 1 / value 2 / ... (see example)
dbGetFieldsIntoDf(fields = "", con, verbose = FALSE, stopifnodata = TRUE)
Vector of one or more strings, with names of the sought fields. See function dbFindFields for how to find names of fields.
A src connection object, as obtained with nodbi::src_mongo() or nodbi::src_sqlite()
Printing additional information if set to TRUE
;
default is FALSE
.
Stops with an error (TRUE
, default) 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.
A data frame with columns corresponding to the sought fields. Note: a column for the record _id will always be included. The maximum number of rows of the returned data frame is equal to, or less than the number of records in the data base.
For more sophisticated data retrieval from the database, see vignette examples and other packages to query mongodb such as mongolite.
# NOT RUN {
# }
# NOT RUN {
dbGetFieldsIntoDf("b1_sponsor.b31_and_b32_status_of_the_sponsor")[1,]
# _id b1_sponsor.b31_and_b32_status_of_the_sponsor
# 1 2004-000015-25-GB Non-commercial / Commercial
dbGetFieldsIntoDf("keyword")[1,]
# _id keyword
# 1 NCT00129259 T1D / type 1 diabetes / type 1 diabetes mellitus
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab