This is a general purpose function to send data request which can be used when there has not been a R equivalent package function to an API endpoint. Underneath this is a wrapper around httr functions with better handling of returned status.

query_epigraphdb(endpoint, params, mode = c("raw", "table"),
  method = c("GET"))

Arguments

endpoint

An EpiGraphDB API endpoint, e.g. "/mr" or "/confounder". Consult the EpiGraphDB API documentation.

params

A list of parameters associated with the query endpoint.

mode

c("raw", "table"), if "table" then the query handler will try to convert the returned data to a tibble dataframe. NOTE: The default mode is "raw" which will NOT convert the returned response to a dataframe. This is different to functions that query topic endpoints which default to return a dataframe. Explicitly specify mode = "table" when needed.

method

Type of HTTP (GET, POST, PUT, etc.) method. Currently only "GET" is supported.

Value

Data from an EpiGraphDB API endpoint.

Examples

# equivalent to `mr(exposure = "Body mass index", outcome = "Coronary heart disease")` query_epigraphdb( endpoint = "/mr", params = list( exposure = "Body mass index", outcome = "Coronary heart disease" ), mode = "table" )
#> # A tibble: 6 x 12 #> exposure_id exposure_name outcome_id outcome_name estimate se p #> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> #> 1 974 Body mass in… 7 Coronary he… 0.389 0.0493 3.42e-15 #> 2 2 Body mass in… 7 Coronary he… 0.397 0.0727 4.79e- 8 #> 3 95 Body mass in… 7 Coronary he… 0.455 0.0931 1.02e- 6 #> 4 2 Body mass in… 8 Coronary he… 0.331 0.0684 1.31e- 6 #> 5 835 Body mass in… 7 Coronary he… 0.360 0.0756 1.94e- 6 #> 6 974 Body mass in… 8 Coronary he… 0.328 0.0731 6.97e- 6 #> # … with 5 more variables: ci_upp <dbl>, ci_low <dbl>, selection <chr>, #> # method <chr>, moescore <dbl>
# /meta/nodes/Gwas/list query_epigraphdb( endpoint = "/meta/nodes/Gwas/list", params = list( limit = 5, offset = 0 ) ) %>% str(1)
#> List of 2 #> $ query : chr "MATCH (n:Gwas) RETURN n SKIP 0 LIMIT 5" #> $ results:List of 5
# error handling tryCatch( query_epigraphdb( endpoint = "/mr", params = list( exposure = NULL, outcome = NULL ) ), error = function(e) { message(e) } )
#> Error in stop_for_status(response, call = sys.call(-1)): Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422). #> Detail: #> $detail #> [1] "exposure and outcome can't be both missing." #> do.call(method, args = list(endpoint = endpoint, params = params, call = call))