R/shorten_URLs.R

Defines functions shorten_url.semnar

Documented in shorten_url.semnar

#' Shorten the URLs of any links in a [`semnar`] object
#'
#' @param object an object of class [`semnar`]. See [add_presentation()].
#' @param service service to use for shortening URLs. Current options are `"V.gd"` (default) and `"Is.gd"`.
#'
#' @return
#' An object of class [`semnar`] with any URLs in `object$link` replace with shorter ones according to the value of `service`.
#'
#' @seealso [add_presentation()] [guess_address()]
#'
#' @export
shorten_url.semnar <- function(object, service = "Is.gd") {
    service <- match.arg(service, choices = c("Is.gd", "V.gd"))
    fun <- switch(service,
                  "Is.gd" = isgd_LinksShorten,
                  "V.gd" = vgd_LinksShorten)
    object$long_link <- object$link
    object$link <- sapply(object$link, function(link) {
        out <- fun(link)
        ifelse(is.null(out), NA, out)
    })
    object
}

Try the semnar package in your browser

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

semnar documentation built on Nov. 3, 2022, 5:06 p.m.