R/get_study_pubs.R

Defines functions get_study_pubs

Documented in get_study_pubs

#' Get Study Publications
#'
#' Retrieve details on any publications that have been associated with the study
#'
#' @param study_id A character string of a valid MTBLS study id
#' @return a `tibble` of study publications
#' @export
#' @examples
#' get_study_pubs('MTBLS375')

get_study_pubs <- function(study_id)
{
  study_pubs <-
    httr::GET(
      paste0(getOption('BASE_URL'),
             '/studies/',
             study_id,
             '/publications')
    )


  study_pubs_parse <- study_pubs %>% httr::content('parsed')


  study_pubs_tibble <- purrr::map(study_pubs_parse$publications, ~ {
    unlist(.) %>% t() %>% dplyr::as_tibble()
  }) %>% dplyr::bind_rows() %>% dplyr::select(-status.termAccession)

  names(study_pubs_tibble)[5] <- 'status'

  return(study_pubs_tibble)

}
wilsontom/metabolighteR documentation built on Feb. 27, 2024, 7:58 p.m.