Skip to content

Instantly share code, notes, and snippets.

@aloth
Created July 24, 2017 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aloth/b061e91229add7dcdd09ac20a518bfb5 to your computer and use it in GitHub Desktop.
Save aloth/b061e91229add7dcdd09ac20a518bfb5 to your computer and use it in GitHub Desktop.
Unshorten URLs in Tableau with R
SCRIPT_STR('
newurl <- .arg1
url <- ""
while(url != newurl){
data <- system(toString(paste0("curl -I ", newurl)), intern=T)
if(sum(grepl("location: ", tolower(data))) == 0){
url <- newurl
}else{
data <- subset(data, tolower(substring(data, 1, 9))=="location:")
stringurl <- substring(data[1], 11, nchar(data[1])-1)
if(substring(stringurl, 1, 4)=="http"){
newurl <- stringurl
}else{
url <- newurl
}
}
}
return(newurl)
',
ATTR([URL Extract]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment