{"action":"closed","issue":{"url":"https://api.github.com/repos/PMassicotte/gtrendsR/issues/271","repository_url":"https://api.github.com/repos/PMassicotte/gtrendsR","labels_url":"https://api.github.com/repos/PMassicotte/gtrendsR/issues/271/labels{/name}","comments_url":"https://api.github.com/repos/PMassicotte/gtrendsR/issues/271/comments","events_url":"https://api.github.com/repos/PMassicotte/gtrendsR/issues/271/events","html_url":"https://github.com/PMassicotte/gtrendsR/issues/271","id":323082632,"number":271,"title":"Loop through a vector to get multiple trends?!","user":{"login":"nikojagochi","id":39292456,"avatar_url":"https://avatars2.githubusercontent.com/u/39292456?v=4","gravatar_id":"","url":"https://api.github.com/users/nikojagochi","html_url":"https://github.com/nikojagochi","followers_url":"https://api.github.com/users/nikojagochi/followers","following_url":"https://api.github.com/users/nikojagochi/following{/other_user}","gists_url":"https://api.github.com/users/nikojagochi/gists{/gist_id}","starred_url":"https://api.github.com/users/nikojagochi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nikojagochi/subscriptions","organizations_url":"https://api.github.com/users/nikojagochi/orgs","repos_url":"https://api.github.com/users/nikojagochi/repos","events_url":"https://api.github.com/users/nikojagochi/events{/privacy}","received_events_url":"https://api.github.com/users/nikojagochi/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-15T06:29:02Z","updated_at":"2018-05-17T11:17:37Z","closed_at":"2018-05-17T11:17:37Z","author_association":"NONE","body":"Hey, hi all.\r\nI'm trying to loop through a vector of keywords to get the trends, but this does not work. I'm not sure if this is due to my lack of understanding or something to do with the function. Could you please have a look and let me know?\r\nI'm not sure why I can't pass a vector as a quoted value inside a function. I've tried Googled solutions with get, parse, eval, dQuote, etc.\r\n\r\nThe trouble is:\r\n- gtrends won't subset a vector, or get the value as quoted, so I can't iterate or run a loop;\r\n- I can't pass the second/third argument when using do.call() - this does not work, work only if i pass the keyword argument and i need to pass the location, time period and \"web\" as arguments;\r\n\r\nkeywords <- c(\"searchterm1\", \"searchterm2\")\r\ntime_period <- c(\"2017-04-01 2018-04-30\")\r\ngeo_location <- \"HK\"\r\n\r\nget_trends <- function(x) {\r\n  for (i in 1:length(x)) {\r\n  y[i] <- gtrends(keywords[i], geo = \"HK\", time = \"2017-04-01 2018-04-30\", gprop = \"web\")$interest_over_time\r\n  }\r\n  return(y)\r\n}\r\nget_trends(keywords) # I get \"NULL\"\r\n\r\ngtrends(\"searchterm1\", geo = geo_location, time = time_period, gprop = \"web\")$interest_over_time # this works, i.e. passing a single quoted value manually (i can't do this for 50 keywords manually :))\r\ngtrends(keyword = keywords[1], geo = geo_location, time = time_period, gprop = \"web\")$interest_over_time # this does not work, I get \"NULL\"\r\n\r\narguments <- c(\"keyword = keywords, geo = geo_location, time = time_period\") # I've tried also as c(\"keyword = keywords\", \"geo = geo_location\", \"time = time_period\")\r\ndo.call(gtrends, list(keywords)$interest_over_time \t# this works, but i can't pass more than one argument\r\ndo.call(gtrends, args) # this does not work\r\ndo.call(gtrends, args)$interest_over_time \t\t\t# this does not work\r\n\r\nKind regards!"}}
{"actor":{"display_login":"nikojagochi"}}