cjbarrie / academictwitteR

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

Update error capturing #309

Open TimBMK opened 2 years ago

TimBMK commented 2 years ago

I've added support for the error capturing mechanism to get_all_tweets() and get_user_timeline(). Among other things, this may help with issue #307, as it provides more variety in terms of test data. In practice I also found it useful to capture errors when retrieving timelines or tweets, as it gives useful information on the data retrieved (e.g., when less data than expected is returned). Furthermore, I added a convenience function to bind errors into a dataframe, comparable to bind_tweets.

All functions that rely on make_query() directly rather than get_tweets() currently do not support error capturing, as they do not store their output in .json files. Looking forward, we might consider adding error capturing mechanisms for these functions as well.

This should not interfere with #308, as the naming conventions remain unchanged. binderrors() merely gathers .json files with the "errors" prefix. The changes in get_all_tweets() and get_user_timeline() only add the "error" T/F variable to be passed on to get_tweets().

chainsawriot commented 2 years ago

@TimBMK TODO

Do you know how to write tests? If yes, it would be useful.

TimBMK commented 2 years ago

I've added the doc files. I'm not familiar with tests other than the basic devtools::check() though. I took a look at your Guide for writing tests, but that only covers handling the dummy API. I can write some tests if you give me some pointers though

TimBMK commented 2 years ago

I've added some test data and a test for bind_errors(). I've basically copied the bind_tweets() tests, since the functionality is more or less equal. Let me know if that's what you'd expect from the tests!

Edit: looks like test coverage is still failing. Could you explain to me why @chainsawriot ?

chainsawriot commented 2 years ago

@TimBMK One of the possible reasons is that many tests assume an envvar TWITTER_BEARER. For PRs from your Github, you can't access the TWITTER_BEARER envvar @cjbarrie has set up here as a Github Secret. I suggest you trying to setup such envvar in your own Github as a secret (just a bogus one will do, you don't need to put your actual bearer token in the envvar).

https://github.com/cjbarrie/academictwitteR/blob/2809432aaea388e7bb016a1f15f24787e8d05586/.github/workflows/test-coverage.yaml#L17-L18

If it still doesn't work, I will try to merge it to a secondary branch here and see how it goes.

chainsawriot commented 2 years ago

@TimBMK I can run (and pass) those bind_errors tests on my machine. So, it is probably due to the Github Secret.

cjbarrie commented 1 year ago

Bumping this. Will this now pass given changed we've made to the gh actions?

TimBMK commented 1 year ago

It would be great if it did, it also seems a little strenuous having to go via @chainsawriot for the actual commits every time. I'm still not sure why the tests fail on my side, I set up the TWITTER_BEARER Secret months ago