R/biolink_bioentity.R

Defines functions biolink_bioentity

Documented in biolink_bioentity

#' Get associated bioentities
#' @param ref_id ref_id
#' @param id id
#' @param query_id query_id

#' @param limit_rows limit_rows

#' @importFrom httr modify_url GET
#' @importFrom tibble as_tibble
#' @importFrom dplyr rename bind_cols filter pull
#' @importFrom glue glue
#' @importFrom rlang .data


#' @rdname biolink_bioentity
#' @export 

biolink_bioentity <- function(ref_id, id, query_id, limit_rows = 100) {

  check_internet()
  
  if(!ref_id %in% vector_refid) {
    stop('Reference not found')
  }
  
  queryid_options <- df_bioentity %>% filter(.data$refid == ref_id) %>% pull(.data$queryid) 
  
  if (!query_id %in% queryid_options) {
    stop(glue('Query not found. \n 
              For the reference {ref_id}, the queries available are: {queryid_options}'))
  }
  

  url <- modify_url(base_url, path = glue('api/bioentity/{ref_id}/{id}/{query_id}'))
  
  resp <- GET(url, user_agent = ua, query = list(rows = limit_rows))
  
  check_response(resp)
  
  parsed <- jsonlite::fromJSON(content(resp, as = "text", encoding = 'UTF-8'), simplifyVector = TRUE)
  
  
  parsed$associations %>% as_tibble()

}
frequena/rbiolink documentation built on May 16, 2020, 10:20 p.m.