get_url: Unshortens URLs created using URL shortening services.

Description Usage Arguments Value Author(s) References Examples

View source: R/get_url.R

Description

The function takes a character vector with shortened URLs and returns a character vector (unless return.df=T) with the resolved URLs. The original shortened URLs are stored in the returned vector as the names attribute of the vector. The function get_url() accepts the optional variables sleep.time (default=0) and return.df (default=FALSE). The variable sleep.time is used to avoid hitting API limit and defines the number of seconds the function will wait before proceeding to the next URL. The default value of sleep.time is zero. The variable return.df is used to return a data frame instead of a character vector. The default value of return.df is FALSE.

Usage

1
get_url(links, sleep.time = 0, return.df = F)

Arguments

links

Shortened URL or list of URLs to be resolved

sleep.time

Number of seconds the function will wait before proceeding to the next URL (optional)

return.df

If return.df=TRUE the function returns a data frame. If return.df=FALSE (default) the function returns a character vector

Value

If return.df=TRUE the function returns a data frame with two columns: the original URL and the resolved URL. If return.df=FALSE (default) the function returns a character vector with the resolved URL.

Author(s)

Marco Bastos

References

The function relies on Hadley Wickham's httr package. Hadley was also very helpful in optimizing the code.

Examples

1
get_url("http://t.co/iWmeUiECAa")

Example output

.Error in curl::curl_fetch_memory(url, handle = handle) : 
  Failed to connect to t.co port 80: Connection refused
                                                                                                http://t.co/iWmeUiECAa 
"Error in curl::curl_fetch_memory(url, handle = handle) : \n  Failed to connect to t.co port 80: Connection refused\n" 

SocialMediaMineR documentation built on May 29, 2017, 11:44 p.m.