gtrendsR Documentation

repository·master·Indexed 18 days ago

https://github.com/pmassicotte/gtrendsr

An R interface for retrieving and visualizing Google Trends data, including keyword popularity over time and geographic distribution. Features the gtrends() function for data retrieval and setHandleParameters() for proxy configuration.

Tokens
547
Snippets
3
Records
3
Agent score
13%

What's inside gtrendsR

  1. Install gtrendsR

    master

    You can install the stable version of gtrendsR from CRAN, install release candidates from the ghrr drat repository, or install the development version directly from GitHub.

    # Install stable version from CRAN
    install.packages("gtrendsR")
    
    # Install release candidates via drat
    install.packages("drat")
    drat:::add("ghrr")
    install.packages("gtrendsR")
    
    # Install development version from GitHub
    if (!require("devtools")) install.packages("devtools")
    devtools::install_github("PMassicotte/gtrendsR")
  2. Retrieve and plot Google Trends data with gtrends()

    master

    The gtrends() function retrieves Google Trends information (number of hits over time and geographic representation) for specific keywords and geographic locations. You can use the standard R plot() function on the resulting object to visualize the trends.

    library(gtrendsR)
    
    # Retrieve trends for keywords 'nhl' and 'nba' in Canada and USA
    res <- gtrends(c("nhl", "nba"), geo = c("CA", "US"))
    
    # Plot the results
    plot(res)
  3. Configure gtrendsR to use a proxy

    master

    If you are working behind a proxy (specifically one using NTLM authentication), use the setHandleParameters() function to configure your connection settings before calling gtrends().

    library(gtrendsR)
    
    # Configure proxy parameters
    setHandleParameters(
      user = "xxxx", 
      password = "*******", 
      domain = "mydomain", 
      proxyhost = "10.111.124.113", 
      proxyport = 8080
    )
    
    # Execute request
    res <- gtrends(c("nhl", "nba"), geo = c("CA", "US"))