1availableTrendLocations = function(...) { 2 locs = twInterfaceObj$doAPICall("trends/available", ...) 3 if (is.null(locs)) { 4 NULL 5 } else { 6 import_trends(locs) 7 } 8} 9 10closestTrendLocations = function(lat, long, ...) { 11 params=list(lat=lat, long=long) 12 13 locs = twInterfaceObj$doAPICall("trends/closest", params=params, ...) 14 if (is.null(locs)) { 15 NULL 16 } else { 17 import_trends(locs) 18 } 19} 20 21buildTrendLocationDf = function(loc_json) { 22 loc_rows = lapply(loc_json, function(x) { 23 return(c(name=x$name, country=x$country, woeid=x$woeid)) 24 }) 25 return(as.data.frame(do.call(rbind, loc_rows), stringsAsFactors=FALSE)) 26 27} 28 29getTrends <- function(woeid, exclude=NULL, ...) { 30 params <- buildCommonArgs(exclude=exclude) 31 params[["id"]] = woeid 32 jsonList <- twInterfaceObj$doAPICall("trends/place", params=params, ...) 33 if (is.null(jsonList)) { 34 return(NULL) 35 } 36 trends <- jsonList[[1]][['trends']] 37 trend_rows = lapply(trends, function(x) { 38 return(c(name=x$name, url=x$url, promoted_content=x$promoted_content, 39 query=x$query, events=x$events, woeid=woeid)) 40 }) 41 return(as.data.frame(do.call(rbind, trend_rows), stringsAsFactors=FALSE)) 42} 43