R/api_key.R

Defines functions is_query_key_set is_search_key_set set_search_key

Documented in set_search_key

#' @title SP2000 API keys
#' @description Apply for the apiKey variable to be used by all search_* functions and zoology_* functions,
#' register for \url{http://sp2000.org.cn/api/document} and use an API key. This function allows users to set this key.
#' Note: The daily API visits of ordinary users are 2000,
#' If you want to apply for increasing the daily API request limit,
#' please fill in the application form \url{http://col.especies.cn/doc/API.docx} and send an email to \email{SP2000CN@ibcas.ac.cn} entitled "Application for increasing API Request Times".
#' @rdname api_key
#' @param key \code{string} Value to set apiKey to (i.e. your API key).
#' @param db \code{string} Set up the database API, db = c("sp2000","zoology").
#' @return A logical of length one, TRUE is the value was set FALSE if not.
#' value is returned inside invisible(), i.e. it is not printed to screen
#' when the function is called.
#' @author Liuyong Ding \email{ly_ding@126.com}
#' @examples
#' \dontrun{
#' #Set the apiKey variable to be used by all search_* functions
#' set_search_key("your apiKey",db = "sp2000")
#'
#' #Set the apiKey variable to be used by all zoology_* functions
#' set_search_key("your apiKey",db = "zoology")
#'
#'}
#' @export
set_search_key <- function(key, db = "sp2000"){
  switch(db,
         sp2000 = {
           Sys.setenv(sp2000_apiKey = key)
         },
         zoology = {
           Sys.setenv(zoology_apiKey = key)
         }
  )
}

is_search_key_set <- function(){
  !identical(Sys.getenv('sp2000_apiKey'), "")
}

#China Animal Scientific Database
is_query_key_set <- function(){
  !identical(Sys.getenv('zoology_apiKey'), "")
}

Try the SP2000 package in your browser

Any scripts or data that you put into this service are public.

SP2000 documentation built on Nov. 8, 2020, 4:41 p.m.