R/starname.R

Defines functions starname

Documented in starname

#' Star Name 
#'
#' This will return infomation about the requested star, 
#' @title Search for star infomation
#' @param star a string of an existing star
#' @return JSON object with infomation about the queried star
#' @keywords Name
#' @examples
#' \dontrun{
#' library(RCurl)
#' library(jsonlite)
#' ###Return Infomation about the Sun
#' starname("Sun")
#' ###Return Infomation about the star HIP1 HD224700 Gli
#' starname("HIP1 HD224700 Gli")
#' ###Return Infomation about all of the stars in the system
#' starname("")
#' }
#' @export
starname <- function(star) {
  internetcheck <- RCurl::url.exists("http://star-api.herokuapp.com", timeout = 10)
  if (internetcheck != TRUE)
    stop('Hacktheuniverse or your internet connection is down')
  urldata <- paste('http://star-api.herokuapp.com/api/v1/stars/', utils::URLencode(star), sep = "")
  data <- RCurl::getURL(urldata)
  dataFrame <- jsonlite::fromJSON(data)
  return(dataFrame)
}
ropensci/RStars documentation built on May 18, 2022, 9:46 a.m.