expand_urls: Expand a vector of (short) URLs using

Description Usage Arguments Value Examples

View source: R/longurl.r

Description

Pass in a vector of URLs (ostensibly "short" URLs) and receive a data frame of the original URLs and expanded URLs

Usage

1
2
3
4
5
6
7
expand_urls(
  urls_to_expand,
  warn = TRUE,
  agent = "longurl-r-package",
  seconds = 5,
  .progress = FALSE
)

Arguments

urls_to_expand

character vector of URLs

warn

show any warnings (API or otherwise) as messages

agent

user agent to use (some sites switchup content based on user agents). Defaults to "'longurl-r-package'".

seconds

number of seconds to wait for a response until giving up. Cannot be <1ms.

.progress

kept for legacy functionality but ignored

Value

a tibble/data frame with the orignial URLs in 'orig_url', expanded URLs in 'expanded_url' and the HTTP 'status_code' of the expanded URL. Completely invalid URLs result in a 'NA' value for 'expanded_url' & 'status_code'.

Examples

1
2
3
4
5
test_urls <- c("http://t.co/D4C7aWYIiA",
               "1.usa.gov/1J6GNoW",
               "ift.tt/1L2Llfr")
big_urls <- expand_urls(test_urls)
head(big_urls)

Example output

Warning messages:
1: In .f(.x[[i]], ...) : Invalid URL: [http://t.co/D4C7aWYIiA]
2: In .f(.x[[i]], ...) : Invalid URL: [1.usa.gov/1J6GNoW]
3: In .f(.x[[i]], ...) : Invalid URL: [ift.tt/1L2Llfr]
# A tibble: 3 x 3
  orig_url               expanded_url status_code
  <chr>                  <lgl>        <lgl>      
1 http://t.co/D4C7aWYIiA NA           NA         
2 1.usa.gov/1J6GNoW      NA           NA         
3 ift.tt/1L2Llfr         NA           NA         

longurl documentation built on July 1, 2020, 10:26 p.m.

Related to expand_urls in longurl...