cjbarrie / academictwitteR

Repo for academictwitteR package to query the Twitter Academic Research Product Track v2 API endpoint.
Other
272 stars 59 forks source link

Why no is_reply = FALSE? #150

Closed thesickish closed 3 years ago

thesickish commented 3 years ago

In get_all_tweets(), you can specify to include only replies (is_reply = TRUE) but not to exclude replies. Maybe this a limitation of the endpoint itself?

cjbarrie commented 3 years ago

Thank you for this. I think this is a mistake on our side. The Twitter API documentation only provides guidance on excluding RTs but this dev message board discussion suggests removing replies also posisble (same for quotes) https://twittercommunity.com/t/exclude-retweets-and-replies/151136.

Thanks for bringing this to our attention.

@chainsawriot and @justinchuntingho this can be fixed just by copying the same format for is_retweet in build_query() here: https://github.com/cjbarrie/academictwitteR/blob/ebaaf96c3d9990246f56d4db83aca2c17e63a8ad/R/build_queryv2.R#L103

In fact, negation also seems to extend to conjunction-required operators like has: . Should all of these default to NULL rather than TRUE, meaning FALSE would mean negation, TRUE inclusion, and NULL either present or absent?

chainsawriot commented 3 years ago

Once again, this is a refactoring problem #142

There must be a better solution.

is_retweet <- TRUE
is_reply <- NULL
is_quote <- FALSE
has_media <- NULL
query <- "whatever"

.process_qparam <- function(param, param_str,query) {
  if(!is.null(param)){
    if(isTRUE(param)) {
      query <- paste(query, param_str)
    } else if(param == FALSE) {
      query <- paste(query, paste0("-", param_str))
    }
  }
  return(query)
}

query <- .process_qparam(is_retweet, "is:retweet", query)
query <- .process_qparam(is_reply, "is:reply", query)
query <- .process_qparam(is_quote, "is:quote", query)
query <- .process_qparam(has_media, "has:media", query)
query
#> [1] "whatever is:retweet -is:quote"

Created on 2021-06-16 by the reprex package (v2.0.0)

cjbarrie commented 3 years ago

Refactored now in my latest PR #158