knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library("epigraphdb")

Methods to query EpiGraphDB

We provide a list of functions that are equivalent to the upstream API endpoints for users to use. For endpoints that don't have equivalent functions, users can use the query_epigraphdb function.

Here we show the two approaches to query MR data from EpiGraphDB, using the mr function and using query_epigraphdb to query the GET /mr endpoint.

mr

df <- mr(
  exposure_trait = "Body mass index",
  outcome_trait = "Coronary heart disease",
  mode = "table"
)
df

GET /mr

df <- query_epigraphdb(
  route = "/mr",
  params = list(
    exposure_trait = "Body mass index",
    outcome_trait = "Coronary heart disease"
  ),
  mode = "table"
)

df

For more information on the API endpoints, please visit:

Returned data format

As a general principle, we offer two modes of the returned data: a table mode (default) that returns a data frame, and a raw mode that preserves the hierarchical structure of the upstream json data and contains other information that might benefit users.

mode = "table"

By default, for ease of use, the query returns a data frame which is a tidyverse tibble:

df <- mr(
  exposure_trait = "Body mass index",
  outcome_trait = "Coronary heart disease"
)
df

mode = "raw"

Alternatively, you can use results_type = "raw" to get the unformatted response from EpiGraphDB API.

response <- mr(
  exposure_trait = "Body mass index",
  outcome_trait = "Coronary heart disease",
  mode = "raw"
)
response %>% str(2)

There are several reasons that a raw mode might benefit you:

  1. The results component preserves the upstream hierarchical json structure that might be useful for users aiming for specific tasks such as rendering network plots or batch post-processing the returned data in a large scale.

  2. The query component returns the cypher query that fetches data from the EpiGraphDB neo4j databases. EpiGraphDB will offer functionality (forthcoming) for users to send cypher queries to the web API that can return more complex query structure (visit our web app for examples). Once you are sufficiently well-versed in cypher you can construct your own refined queries to better suit your needs.



MRCIEU/epigraphdb-r documentation built on Aug. 29, 2022, 4:05 a.m.