R/wiki.R

Defines functions print.available_abbreviation get_abbreviation print.available_wiktionary format.available_wiktionary get_wiktionary print.available_wikipedia format.available_wikipedia get_wikipedia

Documented in get_wikipedia get_wiktionary

#' Open wikipedia page and abbreviations.com page
#'
#' @inheritParams available
#' @export
get_wikipedia <- function(name) {
  # TODO: handle case when we can't open browser
  url <- paste0("https://en.wikipedia.org/wiki/", name)

  structure(url, class = "available_wikipedia")
}

#' @export

format.available_wikipedia <- function(x, ...) {
  browseURL(x[[1]])
  paste0(crayon::bold("Wikipedia: "), crayon::blue(x[[1L]]), "\n")
}

#' @export

print.available_wikipedia <- function(x, ...) {
  cat(format(x, ...))
  invisible(x)
}

#' @rdname get_wikipedia
#' @export
get_wiktionary <- function(name) {
  # TODO: handle case when we can't open browser
  url <- paste0("https://en.wiktionary.org/wiki/", name)

  structure(url, class = "available_wiktionary")
}

#' @export

format.available_wiktionary <- function(x, ...) {
  browseURL(x[[1]])
  paste0(crayon::bold("Wiktionary: "), crayon::blue(x[[1L]]), "\n")
}

#' @export

print.available_wiktionary <- function(x, ...) {
  cat(format(x))
  invisible(x)
}

get_abbreviation <- function(name) {
  # TODO: handle case when we can't open browser
  url <- paste0("http://www.abbreviations.com/", name)

  structure(url, class = "available_abbreviation")
}

print.available_abbreviation <- function(x) {
  browseURL(x[[1]])
  cat(crayon::bold("Abbreviations: "), crayon::blue(x[[1L]]), "\n", sep = "")

  invisible(x)
}

Try the available package in your browser

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

available documentation built on July 11, 2022, 1:05 a.m.