Skip to content
This repository has been archived by the owner on Nov 10, 2024. It is now read-only.

Error in $<-.data.frame(*tmp*, "app", value = "package_rtweet") : #177

Closed
mmarttin opened this issue Feb 9, 2018 · 3 comments
Closed

Error in $<-.data.frame(*tmp*, "app", value = "package_rtweet") : #177

mmarttin opened this issue Feb 9, 2018 · 3 comments

Comments

@mmarttin
Copy link

mmarttin commented Feb 9, 2018

Hi!

I'm quite new to using R and rtweet so, if possible, please respond in somewhat laymans terms... :-)

I'm trying to do an exhaustive search with almost 4100 different search queries (can't spell out all of them here so I just entered one in the example code below), which of course is a lot. So I have the following code that I'm trying to run:

Test_lapply = lapply( c('"search quiry"'), search_tweets, n = 250000, retryonratelimit = TRUE, include_rts = FALSE, geocode = "40.416775,-3.70379,100km")

However, I get the following error message:
Error in $<-.data.frame(tmp, "app", value = "package_rtweet") : replacement has 1 row, data has 0 In addition: Warning message: Rate limit exceeded - 88

I Googled the error and found the following issue tread: https://github.com/mkearney/rtweet/issues/141
However, I get an error message there (the one examplified in the tread) saying that I don't have an ".httr-oauth" file in my current working directory, so I'm not sure what to do.

Any kind of help would be very much appreciated.

@mkearney
Copy link
Collaborator

mkearney commented Feb 9, 2018

@mmarttin: the warning message "Warning message: Rate limit exceeded - 88" is from Twitter; so you're using a correct and active Twitter token. It looks like you may have (a) hit the rate limit between searches and (b) had a search that yielded no results.

What version of rtweet are you using?

packageVersion("rtweet")

I'd recommend installing the latest version from Github (though I just disabled a rate limit check last night, but I don't think that'd cause your issues).

devtools::install_github("mkearney/rtweet")

Also, given the number of search queries and the size of n for each search, I'd recommend constructing a loop so you can cool down between queries and, perhaps, even add a safety valve via tryCatch.

## vector of search queries
search_queries <- c("rstats OR CRAN OR rstudio OR rstatistics", 
  "python OR pynum", "julialang OR juliastats")

## initialize output vector
data <- vector("list", length(search_queries))

## for loop with tryCatch (if search results in error, return an empty
## data frame rather than breaking everything
for (i in seq_along(data)) {
  data[[i]] <- tryCatch(
    search_tweets(
      search_queries[i], n = 250000, retryonratelimit = TRUE, 
      include_rts = FALSE, geocode = "40.416775,-3.70379,100km"),
    error = function(e) return(data.frame())
  )

  ## sleep for 15 mins (bc of Twitter rate limits) between search queries
  Sys.sleep(60 * 15)
}

Are you having any issues with search_tweets() otherwise? I'm going to close this issue for now (I'll still see if you respond though). Of course, if we isolate the problem and it's not fixed, I'll reopen it.

@mkearney mkearney closed this as completed Feb 9, 2018
@mkearney
Copy link
Collaborator

mkearney commented Feb 9, 2018

Oh, and for the record, what tryCatch is doing in the code above is telling R that if there's a code-breaking error, to return an empty data frame instead of the error. This means R will proceed to the next iteration in the loop and when it's done you'll still have what data has been collected. Before you try this loop though, make sure you run some normal searches just to make sure things are working.

@mmarttin
Copy link
Author

mmarttin commented Feb 12, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants