R/gltc.lang.R

Defines functions gltc.lang

Documented in gltc.lang

#' Get Glottocode by language
#'
#' Takes any vector of languages and returns Glottocode.
#' @param x A character vector of the languages (can be written in lower case)
#' @author George Moroz <agricolamz@gmail.com>
#' @seealso \code{\link{aff.lang}}, \code{\link{area.lang}}, \code{\link{country.lang}}, \code{\link{iso.lang}}, \code{\link{lat.lang}}, \code{\link{long.lang}}, \code{\link{subc.lang}}, \code{\link{url.lang}}
#' @examples
#' gltc.lang('Kabardian')
#' gltc.lang(c('Kabardian', 'Udi'))
#' @export

gltc.lang <- function(x) {
  if (typeof(x) == "list") {
    x <- unlist(x)
  }
  glottolog <- lingtypology::glottolog
  vapply(x, function(y) {
    ifelse(
      is.glottolog(y, response = TRUE) == TRUE,
      glottolog[tolower(glottolog$language) %in% tolower(y),]$glottocode,
      NA_character_
    )
  }, character(1))
}
ropensci/lingtypology documentation built on March 17, 2024, 11:13 p.m.