From c74d97866006b8644ed2548adeb7d2ab3ecb5364 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 6 Jun 2021 21:50:07 +0200 Subject: [PATCH 1/2] fix #97 --- R/bind_tweet_jsons.R | 36 +++++++++---------- R/bind_user_jsons.R | 11 +----- .../commtwitter/data_1399005777138962433.json | 1 + tests/testdata/commtwitter/query | 3 ++ .../users_1399005777138962433.json | 1 + tests/testthat/test-bind_tweet_jsons.R | 11 ++++-- tests/testthat/test-bind_user_jsons.R | 33 +++++++++++++++++ 7 files changed, 66 insertions(+), 30 deletions(-) create mode 100644 tests/testdata/commtwitter/data_1399005777138962433.json create mode 100644 tests/testdata/commtwitter/query create mode 100644 tests/testdata/commtwitter/users_1399005777138962433.json create mode 100644 tests/testthat/test-bind_user_jsons.R diff --git a/R/bind_tweet_jsons.R b/R/bind_tweet_jsons.R index 74a9ca6..96ff354 100644 --- a/R/bind_tweet_jsons.R +++ b/R/bind_tweet_jsons.R @@ -1,3 +1,20 @@ +ls_files <- function(data_path, pattern) { + ## parse and bind + files <- + list.files( + path = file.path(data_path), + pattern = pattern, + recursive = T, + include.dirs = T, + full.names = T + ) + + if (length(files) < 1) { + stop(paste0("There are no files matching the pattern `", pattern, "` in the specified directory."), call. = FALSE) + } + return(files) +} + #' Bind tweets stored as JSON files #' #' @param data_path string, file path to directory of stored tweets data saved as data_*id*.json @@ -10,24 +27,7 @@ #' bind_tweet_jsons(data_path = "data/") #' } bind_tweet_jsons <- function(data_path) { - if(substr(data_path, nchar(data_path), nchar(data_path)) != "/"){ - data_path <- paste0(data_path,"/") - } - # parse and bind - files <- - list.files( - path = file.path(data_path), - pattern = "^data_", - recursive = T, - include.dirs = T - ) - - if(length(files)<1){ - stop("There are no files matching the pattern `data_` in the specified directory.") - } - - files <- paste(data_path, files, sep = "") - + files <- ls_files(data_path, "^data_") pb = utils::txtProgressBar(min = 0, max = length(files), initial = 0) diff --git a/R/bind_user_jsons.R b/R/bind_user_jsons.R index 8b31b70..682f471 100644 --- a/R/bind_user_jsons.R +++ b/R/bind_user_jsons.R @@ -10,16 +10,7 @@ #' bind_user_jsons("data_path = "data/"") #' } bind_user_jsons <- function(data_path) { - # parse and bind - files <- - list.files( - path = file.path(data_path), - pattern = "^users_", - recursive = T, - include.dirs = T - ) - files <- paste(data_path, files, sep = "") - + files <- ls_files(data_path, "^users_") pb = utils::txtProgressBar(min = 0, max = length(files), initial = 0) diff --git a/tests/testdata/commtwitter/data_1399005777138962433.json b/tests/testdata/commtwitter/data_1399005777138962433.json new file mode 100644 index 0000000..2a459c8 --- /dev/null +++ b/tests/testdata/commtwitter/data_1399005777138962433.json @@ -0,0 +1 @@ +[{"source":"Twitter Web App","text":"RT @NatComm: Are you interested in a career outside of academia? Check out NCA’s “#AltAC in COM” YouTube playlist, which includes videos fr…","lang":"en","entities":{"mentions":[{"start":3,"end":11,"username":"NatComm"}],"hashtags":[{"start":82,"end":88,"tag":"AltAC"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1391807748346683397"}],"possibly_sensitive":false,"created_at":"2021-06-02T21:15:24.000Z","id":"1400199391961620488","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}},{"domain":{"id":"46","name":"Brand Category","description":"Categories within Brand Verticals that narrow down the scope of Brands"},"entity":{"id":"781974596752842752","name":"Services"}},{"domain":{"id":"47","name":"Brand","description":"Brands and Companies"},"entity":{"id":"10029382357","name":"YouTube"}}],"conversation_id":"1400199391961620488","author_id":"45648666"},{"source":"Twitter for Android","text":"RT @NatComm: Comm Ph.D. students: It’s not too late to apply for NCA’s virtual Doctoral Honors Seminar! The seminar offers students a speci…","lang":"en","entities":{"mentions":[{"start":3,"end":11,"username":"NatComm"}],"hashtags":{},"annotations":[{"start":13,"end":19,"probability":0.486,"type":"Organization","normalized_text":"Comm Ph"},{"start":65,"end":67,"probability":0.6134,"type":"Organization","normalized_text":"NCA"}],"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399780280710221834"}],"possibly_sensitive":false,"created_at":"2021-06-02T14:53:43.000Z","id":"1400103340495810561","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":{},"conversation_id":"1400103340495810561","author_id":"956624418"},{"source":"Twitter Web App","text":"RT @NatComm: Comm Ph.D. students: It’s not too late to apply for NCA’s virtual Doctoral Honors Seminar! The seminar offers students a speci…","lang":"en","entities":{"mentions":[{"start":3,"end":11,"username":"NatComm"}],"hashtags":{},"annotations":[{"start":13,"end":19,"probability":0.486,"type":"Organization","normalized_text":"Comm Ph"},{"start":65,"end":67,"probability":0.6134,"type":"Organization","normalized_text":"NCA"}],"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399780280710221834"}],"possibly_sensitive":false,"created_at":"2021-06-01T18:37:49.000Z","id":"1399797349296197635","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":{},"conversation_id":"1399797349296197635","author_id":"1145936974064177152"},{"source":"Twitter for Advertisers","text":"Comm Ph.D. students: It’s not too late to apply for NCA’s virtual Doctoral Honors Seminar! The seminar offers students a special opportunity to work with distinguished Communication faculty members. Application deadline: June 4. Apply today! https://t.co/stoYToSHfz #CommTwitter","lang":"en","entities":{"mentions":{},"hashtags":[{"start":266,"end":278,"tag":"CommTwitter"}],"annotations":[{"start":0,"end":6,"probability":0.5457,"type":"Organization","normalized_text":"Comm Ph"},{"start":52,"end":54,"probability":0.6734,"type":"Organization","normalized_text":"NCA"}],"urls":[{"start":242,"end":265,"url":"https://t.co/stoYToSHfz","expanded_url":"http://Natcom.org/DHS","display_url":"Natcom.org/DHS","images":[{"url":"https://pbs.twimg.com/news_img/1399780289744760838/MfDN54Vm?format=png&name=orig","width":400,"height":400},{"url":"https://pbs.twimg.com/news_img/1399780289744760838/MfDN54Vm?format=png&name=150x150","width":150,"height":150}],"status":200,"title":"NCA Doctoral Honors Seminar","description":"The NCA Doctoral Honors Seminars (DHS) bring together promising doctoral students and distinguished faculty members from across the discipline and around the nation to discuss current topics in Communication.","unwound_url":"https://www.natcom.org/convention-events/nca-sponsored-events/nca-doctoral-honors-seminar"}]},"referenced_tweets":{},"possibly_sensitive":false,"created_at":"2021-06-01T17:30:00.000Z","id":"1399780280710221834","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":5,"quote_count":0},"context_annotations":{},"conversation_id":"1399780280710221834","author_id":"17880989"},{"source":"Twitter Web App","text":"Today is the deadline for Communication department chairs to register for NCA’s virtual Chairs’ Summer Institute! Themed, “Leadership Challenges in a Changing World,” it will be held June 25-26, 2021. Registration deadline: June 1. https://t.co/AQhHUXbAhH #CommTwitter","lang":"en","entities":{"mentions":{},"hashtags":[{"start":256,"end":268,"tag":"CommTwitter"}],"annotations":[{"start":74,"end":76,"probability":0.785,"type":"Organization","normalized_text":"NCA"}],"urls":[{"start":232,"end":255,"url":"https://t.co/AQhHUXbAhH","expanded_url":"http://Natcom.org/CSI","display_url":"Natcom.org/CSI","images":[{"url":"https://pbs.twimg.com/news_img/1398021208306860037/Ks49f37T?format=png&name=orig","width":430,"height":400},{"url":"https://pbs.twimg.com/news_img/1398021208306860037/Ks49f37T?format=png&name=150x150","width":150,"height":150}],"status":200,"title":"NCA Chairs' Summer Institute","description":"2021 VIRTUAL ","unwound_url":"https://www.natcom.org/convention-events/nca-sponsored-events/nca-chairs-summer-institute"}]},"referenced_tweets":{},"possibly_sensitive":false,"created_at":"2021-06-01T16:30:33.000Z","id":"1399765322509557763","public_metrics":{"retweet_count":0,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":{},"conversation_id":"1399765322509557763","author_id":"17880989"},{"source":"Twitter Web App","text":"RT @waqasejazch: Oh! it looks like I am just three followers shy from my first 100. What a better way for a comm scholar to get there durin…","lang":"en","entities":{"mentions":[{"start":3,"end":15,"username":"waqasejazch"}],"hashtags":{},"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399278878548533248"}],"possibly_sensitive":false,"created_at":"2021-05-31T11:44:41.000Z","id":"1399330992825913344","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":{},"conversation_id":"1399330992825913344","author_id":"1665378883"},{"source":"Twitter for Android","text":"RT @waqasejazch: Oh! it looks like I am just three followers shy from my first 100. What a better way for a comm scholar to get there durin…","lang":"en","entities":{"mentions":[{"start":3,"end":15,"username":"waqasejazch"}],"hashtags":{},"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399278878548533248"}],"possibly_sensitive":false,"created_at":"2021-05-31T11:39:03.000Z","id":"1399329574115282944","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":{},"conversation_id":"1399329574115282944","author_id":"1085578910853746688"},{"source":"Twitter Web App","text":"Oh! it looks like I am just three followers shy from my first 100. What a better way for a comm scholar to get there during #ica21. \nSo, if you are interested in reading about comm research originating from the Global South, you know what to do :-) #AcademicTwitter #Commtwitter","lang":"en","entities":{"mentions":{},"hashtags":[{"start":124,"end":130,"tag":"ica21"},{"start":249,"end":265,"tag":"AcademicTwitter"},{"start":266,"end":278,"tag":"Commtwitter"}],"annotations":[{"start":211,"end":222,"probability":0.6783,"type":"Place","normalized_text":"Global South"}],"urls":{}},"referenced_tweets":{},"possibly_sensitive":false,"created_at":"2021-05-31T08:17:36.000Z","id":"1399278878548533248","public_metrics":{"retweet_count":2,"reply_count":0,"like_count":6,"quote_count":0},"context_annotations":{},"conversation_id":"1399278878548533248","author_id":"2758518175"},{"source":"Twitter for Android","text":"RT @ICASECAC: Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you ha…","lang":"en","entities":{"mentions":[{"start":3,"end":12,"username":"ICASECAC"}],"hashtags":[{"start":45,"end":51,"tag":"ica21"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399005777138962433"}],"possibly_sensitive":false,"created_at":"2021-05-30T16:23:10.000Z","id":"1399038684834504712","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399038684834504712","author_id":"936983330"},{"source":"Twitter for Android","text":"RT @ICASECAC: Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you ha…","lang":"en","entities":{"mentions":[{"start":3,"end":12,"username":"ICASECAC"}],"hashtags":[{"start":45,"end":51,"tag":"ica21"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399005777138962433"}],"possibly_sensitive":false,"created_at":"2021-05-30T15:12:41.000Z","id":"1399020950369226755","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399020950369226755","author_id":"34739420"},{"source":"Twitter for Android","text":"RT @ICASECAC: Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you ha…","lang":"en","entities":{"mentions":[{"start":3,"end":12,"username":"ICASECAC"}],"hashtags":[{"start":45,"end":51,"tag":"ica21"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399005777138962433"}],"possibly_sensitive":false,"created_at":"2021-05-30T14:37:40.000Z","id":"1399012137608097793","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399012137608097793","author_id":"8445422"},{"source":"Twitter for Android","text":"RT @ICASECAC: Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you ha…","lang":"en","entities":{"mentions":[{"start":3,"end":12,"username":"ICASECAC"}],"hashtags":[{"start":45,"end":51,"tag":"ica21"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399005777138962433"}],"possibly_sensitive":false,"created_at":"2021-05-30T14:35:11.000Z","id":"1399011512480681984","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399011512480681984","author_id":"460255655"},{"source":"Twitter for iPhone","text":"RT @ICASECAC: Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you ha…","lang":"en","entities":{"mentions":[{"start":3,"end":12,"username":"ICASECAC"}],"hashtags":[{"start":45,"end":51,"tag":"ica21"}],"annotations":{},"urls":{}},"referenced_tweets":[{"type":"retweeted","id":"1399005777138962433"}],"possibly_sensitive":false,"created_at":"2021-05-30T14:15:43.000Z","id":"1399006613852278785","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":0,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399006613852278785","author_id":"2832986725"},{"source":"Twitter for iPhone","text":"Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you have bonus points. #ICA21 #commtwitter #secac","lang":"en","entities":{"mentions":{},"hashtags":[{"start":31,"end":37,"tag":"ica21"},{"start":142,"end":148,"tag":"ICA21"},{"start":149,"end":161,"tag":"commtwitter"},{"start":162,"end":168,"tag":"secac"}],"annotations":{},"urls":{}},"referenced_tweets":{},"possibly_sensitive":false,"created_at":"2021-05-30T14:12:24.000Z","id":"1399005777138962433","public_metrics":{"retweet_count":5,"reply_count":0,"like_count":12,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399005777138962433","author_id":"983366304466907136"}] diff --git a/tests/testdata/commtwitter/query b/tests/testdata/commtwitter/query new file mode 100644 index 0000000..4a4af66 --- /dev/null +++ b/tests/testdata/commtwitter/query @@ -0,0 +1,3 @@ +#commtwitter +2021-05-30T00:00:00Z +2021-06-05T23:59:59Z diff --git a/tests/testdata/commtwitter/users_1399005777138962433.json b/tests/testdata/commtwitter/users_1399005777138962433.json new file mode 100644 index 0000000..b8a664d --- /dev/null +++ b/tests/testdata/commtwitter/users_1399005777138962433.json @@ -0,0 +1 @@ +{"users":[{"username":"rahulmitra","location":"Detroit,MI","public_metrics":{"followers_count":1939,"following_count":2671,"tweet_count":16466,"listed_count":105},"verified":false,"url":"https://t.co/T5l6L9BrrE","pinned_tweet_id":"1360333484846444554","name":"Dr. Rahul Mitra 🌈","description":"I study env. organizing, CSR #orgcomm #envcomm. Assoc Prof @WayneState @WSU_COM, Dir. #RISElab #DetroitWaterStories, @LifeatPurdue alum. ❤ #publicscholarship","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/T5l6L9BrrE","expanded_url":"http://www.rahulmitraphd.com","display_url":"rahulmitraphd.com"}]},"description":{"hashtags":[{"start":29,"end":37,"tag":"orgcomm"},{"start":38,"end":46,"tag":"envcomm"},{"start":86,"end":94,"tag":"RISElab"},{"start":95,"end":115,"tag":"DetroitWaterStories"},{"start":139,"end":157,"tag":"publicscholarship"}],"mentions":[{"start":59,"end":70,"username":"WayneState"},{"start":71,"end":79,"username":"WSU_COM"},{"start":117,"end":130,"username":"LifeatPurdue"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/1394300766823895040/fS-tV4kA_normal.jpg","created_at":"2009-06-08T19:35:34.000Z","id":"45648666"},{"username":"NatComm","location":"Washington, DC","public_metrics":{"followers_count":12245,"following_count":1053,"tweet_count":11987,"listed_count":417},"verified":true,"url":"http://t.co/nPhK8jTwuD","name":"NCA","description":"The National Communication Association is a scholarly society that enables & supports its members’ Communication research & teaching.","protected":false,"entities":{"url":{"urls":[{"start":0,"end":22,"url":"http://t.co/nPhK8jTwuD","expanded_url":"http://www.natcom.org","display_url":"natcom.org"}]},"description":{"hashtags":{},"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1110927896435150849/M16LTNRp_normal.png","created_at":"2008-12-04T22:04:19.000Z","id":"17880989"},{"username":"OrgComInTheNews","public_metrics":{"followers_count":480,"following_count":277,"tweet_count":959,"listed_count":11},"verified":false,"url":"https://t.co/GvEJcYb4fr","name":"Org Com In The News","description":"Sharing organizational communication cases in the news, and celebrating #OrgComm teachers and our awesome #OrgCommStudents. 👩🏽‍🎓👨🏻‍🎓","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/GvEJcYb4fr","expanded_url":"http://www.orgcominthenews.com","display_url":"orgcominthenews.com"}]},"description":{"hashtags":[{"start":72,"end":80,"tag":"OrgComm"},{"start":106,"end":122,"tag":"OrgCommStudents"}],"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1081676548443439104/1XgFdpFl_normal.jpg","created_at":"2012-11-19T02:52:07.000Z","id":"956624418"},{"username":"adil_iis","location":"Neu-Delhi, Republik Indien","public_metrics":{"followers_count":222,"following_count":142,"tweet_count":1278,"listed_count":2},"verified":false,"url":"https://t.co/Zyf8RHx0rW","name":"Syed Adil Shamim Andrabi","description":"IIS\nIndian Information Service \nBureau of Outreach and Communication \n(DAVP)\nMinistry of I&B\nFr IIFO/ PRO ICMR \nMinistry of Health and Family Welfare\nNew Delhi","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/Zyf8RHx0rW","expanded_url":"http://davp.nic.in","display_url":"davp.nic.in"}]},"description":{"hashtags":{},"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1261391537675530240/R4id22hu_normal.jpg","created_at":"2019-07-02T06:07:19.000Z","id":"1145936974064177152"},{"username":"ajeenarose","location":"Tirunelveli, India","public_metrics":{"followers_count":33,"following_count":458,"tweet_count":92,"listed_count":0},"verified":false,"url":"","name":"Ajeena Rose","description":"PhD🏅, A dot in the LINE.🍃","protected":false,"entities":{"url":{"urls":{}},"description":{"hashtags":{},"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1399162824123850755/7Sr8PtBo_normal.jpg","created_at":"2013-08-12T15:34:12.000Z","id":"1665378883"},{"username":"waqasejazch","location":"Worldwide","public_metrics":{"followers_count":106,"following_count":94,"tweet_count":482,"listed_count":2},"verified":false,"url":"","name":"Waqas Ejaz, PhD📊","description":"Asst. Prof at S3H @Official_NUST | Alum @IfMk | Tweets about #polcomm research, and #rstats. Pushing 4 more research representation from GlobalSouth","protected":false,"entities":{"url":{"urls":{}},"description":{"hashtags":[{"start":61,"end":69,"tag":"polcomm"},{"start":84,"end":91,"tag":"rstats"}],"mentions":[{"start":18,"end":32,"username":"Official_NUST"},{"start":40,"end":45,"username":"IfMk"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/1219538725836935168/hIN0L3bj_normal.jpg","created_at":"2014-08-23T11:13:32.000Z","id":"2758518175"},{"username":"LaraWolfers","public_metrics":{"followers_count":359,"following_count":493,"tweet_count":435,"listed_count":4},"verified":false,"url":"https://t.co/I6inXyQHR2","pinned_tweet_id":"1287691621010636803","name":"Lara Wolfers","description":"Doctoral student @IWMtue. Research on mobile & social media use, coping with stress & media use in the family. Tweets about research and academic parenting.","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/I6inXyQHR2","expanded_url":"https://www.iwm-tuebingen.de/www/en/personen/ma.html?uid=lwolfers","display_url":"iwm-tuebingen.de/www/en/persone…"}]},"description":{"hashtags":{},"mentions":[{"start":17,"end":24,"username":"IWMtue"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/1085579140911296512/q488WZrd_normal.jpg","created_at":"2019-01-16T16:45:56.000Z","id":"1085578910853746688"},{"username":"TUDr_AS","location":"Philadelphia, PA","public_metrics":{"followers_count":723,"following_count":154,"tweet_count":6871,"listed_count":15},"verified":false,"url":"https://t.co/cKQ27trfEX","name":"Dr. Adrienne Shaw","description":"Associate Professor, Temple U, Klein College, Department of Media Studies and Production","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/cKQ27trfEX","expanded_url":"http://smc.temple.edu/msp/","display_url":"smc.temple.edu/msp/"}]},"description":{"hashtags":{},"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1185222845539979266/Y3W2pLni_normal.jpg","created_at":"2012-11-09T14:04:04.000Z","id":"936983330"},{"username":"ICASECAC","public_metrics":{"followers_count":1335,"following_count":1157,"tweet_count":360,"listed_count":7},"verified":false,"url":"https://t.co/pR3GTgK0G7","name":"ICA Student & Early Career Members","description":"Student & Early Career Scholars Community @ICAhdq #SECAC #ICA21 #Socialjustice #Care","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/pR3GTgK0G7","expanded_url":"https://www.icahdq.org/group/sec","display_url":"icahdq.org/group/sec"}]},"description":{"hashtags":[{"start":50,"end":56,"tag":"SECAC"},{"start":57,"end":63,"tag":"ICA21"},{"start":64,"end":78,"tag":"Socialjustice"},{"start":79,"end":84,"tag":"Care"}],"mentions":[{"start":42,"end":49,"username":"ICAhdq"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/1132272824113127426/m2OtzFAt_normal.png","created_at":"2018-04-09T15:29:31.000Z","id":"983366304466907136"},{"username":"adrishaw","public_metrics":{"followers_count":3409,"following_count":821,"tweet_count":17920,"listed_count":105},"verified":false,"url":"https://t.co/cJ9FKh9x7g","name":"Adrienne Shaw","description":"Writer of books, player of games, maker of food, and custodian of plants that are really just doing their own thing.","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/cJ9FKh9x7g","expanded_url":"http://www.adrienneshaw.com","display_url":"adrienneshaw.com"}]},"description":{"hashtags":{},"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/521855298969948160/VNlsiOxg_normal.jpeg","created_at":"2009-04-23T21:40:18.000Z","id":"34739420"},{"username":"endalk2006","location":"St Paul, MN","public_metrics":{"followers_count":19258,"following_count":4675,"tweet_count":11104,"listed_count":109},"verified":false,"url":"https://t.co/KnWqCRaFk4","name":"Endalk","description":"Assistant Professor at @HamlineU Views are my own. Research: Activism, Journalism & Technology in Africa. Retweets & likes are not endorsements. Husband & Dad.","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/KnWqCRaFk4","expanded_url":"http://endalk.blog","display_url":"endalk.blog"}]},"description":{"hashtags":{},"mentions":[{"start":23,"end":32,"username":"HamlineU"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/378800000608539530/5019ea88360ccb49a515cc61253658f6_normal.jpeg","created_at":"2007-08-26T18:36:32.000Z","id":"8445422"},{"username":"wunpini_fm","location":"Tamale| Cienfuegos| GA","public_metrics":{"followers_count":13475,"following_count":868,"tweet_count":189683,"listed_count":115},"verified":false,"url":"https://t.co/c4yxpWd7Tf","pinned_tweet_id":"1351222181758455816","name":"Wunpini F. Mohammed, Ph.D.","description":"Asst. Prof. | Journo/Scholar| @AfroGradChat\nViews=Mine\n📝@AJEnglish @globalvoices @Popula\n \nGriotte📚🎤🥁, Feminist, Dagbana🇬🇭🇨🇺🇮🇷","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/c4yxpWd7Tf","expanded_url":"http://wunpini.com","display_url":"wunpini.com"}]},"description":{"hashtags":{},"mentions":[{"start":30,"end":43,"username":"AfroGradChat"},{"start":56,"end":66,"username":"AJEnglish"},{"start":67,"end":80,"username":"globalvoices"},{"start":81,"end":88,"username":"Popula"}]}},"profile_image_url":"https://pbs.twimg.com/profile_images/1395862437807763457/5HrXClSg_normal.jpg","created_at":"2012-01-10T15:18:02.000Z","id":"460255655"},{"username":"IttefaqM","location":"🇵🇰🇩🇪🇺🇸","public_metrics":{"followers_count":1208,"following_count":1945,"tweet_count":10607,"listed_count":17},"verified":false,"url":"https://t.co/Z5tKwGYxqc","name":"Muhammad Ittefaq","description":"I research #HealthCommunication #Misinformation #Digitalmedia #Globalhealth #Vaccines","protected":false,"entities":{"url":{"urls":[{"start":0,"end":23,"url":"https://t.co/Z5tKwGYxqc","expanded_url":"https://muhammadittefaq.com/","display_url":"muhammadittefaq.com"}]},"description":{"hashtags":[{"start":11,"end":31,"tag":"HealthCommunication"},{"start":32,"end":47,"tag":"Misinformation"},{"start":48,"end":61,"tag":"Digitalmedia"},{"start":62,"end":75,"tag":"Globalhealth"},{"start":76,"end":85,"tag":"Vaccines"}],"mentions":{}}},"profile_image_url":"https://pbs.twimg.com/profile_images/1206315213601017856/spTo6nAX_normal.jpg","created_at":"2014-09-26T13:16:14.000Z","id":"2832986725"}],"tweets":[{"source":"Twitter for Advertisers","text":"Are you interested in a career outside of academia? Check out NCA’s “#AltAC in COM” YouTube playlist, which includes videos from all three sessions of the recent virtual workshop series! https://t.co/vO3Sy7smj4 #CommTwitter #career #phdchat","lang":"en","possibly_sensitive":false,"created_at":"2021-05-10T17:30:00.000Z","id":"1391807748346683397","entities":{"hashtags":[{"start":69,"end":75,"tag":"AltAC"},{"start":211,"end":223,"tag":"CommTwitter"},{"start":224,"end":231,"tag":"career"},{"start":232,"end":240,"tag":"phdchat"}],"annotations":[{"start":84,"end":90,"probability":0.3373,"type":"Organization","normalized_text":"YouTube"}],"urls":[{"start":187,"end":210,"url":"https://t.co/vO3Sy7smj4","expanded_url":"https://bit.ly/2Q5qMuV","display_url":"bit.ly/2Q5qMuV","images":[{"url":"https://pbs.twimg.com/news_img/1391807750804582404/VX9Wp9Sn?format=jpg&name=orig","width":1280,"height":720},{"url":"https://pbs.twimg.com/news_img/1391807750804582404/VX9Wp9Sn?format=jpg&name=150x150","width":150,"height":150}],"status":200,"title":"#AltAC in COM: Day 1: From Academy to Industry presented by Dr. Christine E. Kiesinger","description":"#AltAC in COM: Exploring Career Options Beyond the Academy for Communication PhDsWorkshop Title: Leaving Home: Finding Place, Purpose and Possibilities Outsi...","unwound_url":"https://www.youtube.com/watch?v=5yHsZcys44E&list=PLaETCkw7w_Q8qHrMC8fE--PU2VLSPpAWf"}]},"public_metrics":{"retweet_count":5,"reply_count":0,"like_count":12,"quote_count":3},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}},{"domain":{"id":"46","name":"Brand Category","description":"Categories within Brand Verticals that narrow down the scope of Brands"},"entity":{"id":"781974596752842752","name":"Services"}},{"domain":{"id":"47","name":"Brand","description":"Brands and Companies"},"entity":{"id":"10029382357","name":"YouTube"}},{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847546154439000064","name":"Education","description":"Education through the lens of those passionate about resources and news. This topic excludes Education policy and reform."}},{"domain":{"id":"66","name":"Interests and Hobbies Category","description":"A grouping of interests and hobbies entities, like Novelty Food or Destinations"},"entity":{"id":"852247095461371904","name":"Graduate school","description":"Graduate school"}}],"conversation_id":"1391807748346683397","author_id":"17880989"},{"source":"Twitter for Advertisers","text":"Comm Ph.D. students: It’s not too late to apply for NCA’s virtual Doctoral Honors Seminar! The seminar offers students a special opportunity to work with distinguished Communication faculty members. Application deadline: June 4. Apply today! https://t.co/stoYToSHfz #CommTwitter","lang":"en","possibly_sensitive":false,"created_at":"2021-06-01T17:30:00.000Z","id":"1399780280710221834","entities":{"hashtags":[{"start":266,"end":278,"tag":"CommTwitter"}],"annotations":[{"start":0,"end":6,"probability":0.5457,"type":"Organization","normalized_text":"Comm Ph"},{"start":52,"end":54,"probability":0.6734,"type":"Organization","normalized_text":"NCA"}],"urls":[{"start":242,"end":265,"url":"https://t.co/stoYToSHfz","expanded_url":"http://Natcom.org/DHS","display_url":"Natcom.org/DHS","images":[{"url":"https://pbs.twimg.com/news_img/1399780289744760838/MfDN54Vm?format=png&name=orig","width":400,"height":400},{"url":"https://pbs.twimg.com/news_img/1399780289744760838/MfDN54Vm?format=png&name=150x150","width":150,"height":150}],"status":200,"title":"NCA Doctoral Honors Seminar","description":"The NCA Doctoral Honors Seminars (DHS) bring together promising doctoral students and distinguished faculty members from across the discipline and around the nation to discuss current topics in Communication.","unwound_url":"https://www.natcom.org/convention-events/nca-sponsored-events/nca-doctoral-honors-seminar"}]},"public_metrics":{"retweet_count":2,"reply_count":0,"like_count":5,"quote_count":0},"context_annotations":{},"conversation_id":"1399780280710221834","author_id":"17880989"},{"source":"Twitter Web App","text":"Oh! it looks like I am just three followers shy from my first 100. What a better way for a comm scholar to get there during #ica21. \nSo, if you are interested in reading about comm research originating from the Global South, you know what to do :-) #AcademicTwitter #Commtwitter","lang":"en","possibly_sensitive":false,"created_at":"2021-05-31T08:17:36.000Z","id":"1399278878548533248","entities":{"hashtags":[{"start":124,"end":130,"tag":"ica21"},{"start":249,"end":265,"tag":"AcademicTwitter"},{"start":266,"end":278,"tag":"Commtwitter"}],"annotations":[{"start":211,"end":222,"probability":0.6783,"type":"Place","normalized_text":"Global South"}],"urls":{}},"public_metrics":{"retweet_count":2,"reply_count":0,"like_count":6,"quote_count":0},"context_annotations":{},"conversation_id":"1399278878548533248","author_id":"2758518175"},{"source":"Twitter for iPhone","text":"Who are next 11 followers from #ica21 who wants us to follow them back. If you are an early career or graduate student you have bonus points. #ICA21 #commtwitter #secac","lang":"en","possibly_sensitive":false,"created_at":"2021-05-30T14:12:24.000Z","id":"1399005777138962433","entities":{"hashtags":[{"start":31,"end":37,"tag":"ica21"},{"start":142,"end":148,"tag":"ICA21"},{"start":149,"end":161,"tag":"commtwitter"},{"start":162,"end":168,"tag":"secac"}],"annotations":{},"urls":{}},"public_metrics":{"retweet_count":5,"reply_count":0,"like_count":12,"quote_count":0},"context_annotations":[{"domain":{"id":"65","name":"Interests and Hobbies Vertical","description":"Top level interests and hobbies groupings, like Food or Travel"},"entity":{"id":"847544972781826048","name":"Careers","description":"Careers"}}],"conversation_id":"1399005777138962433","author_id":"983366304466907136"}]} diff --git a/tests/testthat/test-bind_tweet_jsons.R b/tests/testthat/test-bind_tweet_jsons.R index 3c19002..d0cc712 100644 --- a/tests/testthat/test-bind_tweet_jsons.R +++ b/tests/testthat/test-bind_tweet_jsons.R @@ -1,5 +1,4 @@ -context("bind_tweet_jsons") - +## context("bind_tweet_jsons") empty_dir <- tempdir() @@ -23,3 +22,11 @@ test_that("Error on finding no jsons to bind", { expect_error(bind_tweet_jsons(temp_dir)) }) + +test_that("real data", { + expect_error(bind_tweet_jsons("../testdata/commtwitter"), NA) +}) + +test_that("trailing slash", { + expect_error(bind_tweet_jsons("../testdata/commtwitter/"), NA) +}) diff --git a/tests/testthat/test-bind_user_jsons.R b/tests/testthat/test-bind_user_jsons.R new file mode 100644 index 0000000..ba8d4a6 --- /dev/null +++ b/tests/testthat/test-bind_user_jsons.R @@ -0,0 +1,33 @@ +## context("bind_tweet_jsons") + +empty_dir <- tempdir(check = TRUE) + +my_cars <- mtcars +my_cars$model <- rownames(my_cars) + +jsonlite::write_json(list(users = my_cars, tweets = iris), + path = file.path(empty_dir, "users_1.json")) +jsonlite::write_json(list(users = my_cars, tweets = iris), + path = file.path(empty_dir, "users_2.json")) + +test_that("Expect sucess in binding two jsons", { + expect_equal(bind_user_jsons(empty_dir), + dplyr::bind_rows(my_cars,my_cars)) +}) + +unlink(empty_dir, recursive = TRUE) +temp_dir <- tempdir() + +test_that("Error on finding no jsons to bind", { + expect_error(bind_tweet_jsons(temp_dir)) +}) + + +test_that("real data: data_path without trailing slash #97", { + expect_error(bind_user_jsons("../testdata/commtwitter"), NA) +}) + +test_that("real data: data_path with trailing slash #97", { + expect_error(bind_user_jsons("../testdata/commtwitter/"), NA) +}) + From 7a16b18f3801ac77a3987bacd439d2672ef91f6b Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Sun, 6 Jun 2021 22:07:59 +0200 Subject: [PATCH 2/2] Don't delete aka unlink the session's temp directory; clean up after testing --- tests/testthat/test-bind_tweet_jsons.R | 9 +++++++-- tests/testthat/test-bind_user_jsons.R | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/testthat/test-bind_tweet_jsons.R b/tests/testthat/test-bind_tweet_jsons.R index d0cc712..c452a78 100644 --- a/tests/testthat/test-bind_tweet_jsons.R +++ b/tests/testthat/test-bind_tweet_jsons.R @@ -1,6 +1,7 @@ ## context("bind_tweet_jsons") -empty_dir <- tempdir() +empty_dir <- paste0(tempdir(), "/", paste0(sample(letters, 20), collapse = "")) +dir.create(empty_dir) my_cars <- mtcars my_cars$model <- rownames(my_cars) @@ -16,7 +17,9 @@ test_that("Expect sucess in binding two jsons", { }) unlink(empty_dir, recursive = TRUE) -temp_dir <- tempdir() + +temp_dir <- paste0(tempdir(), "/", paste0(sample(letters, 20), collapse = "")) +dir.create(temp_dir) test_that("Error on finding no jsons to bind", { expect_error(bind_tweet_jsons(temp_dir)) @@ -30,3 +33,5 @@ test_that("real data", { test_that("trailing slash", { expect_error(bind_tweet_jsons("../testdata/commtwitter/"), NA) }) + +unlink(temp_dir) diff --git a/tests/testthat/test-bind_user_jsons.R b/tests/testthat/test-bind_user_jsons.R index ba8d4a6..52de895 100644 --- a/tests/testthat/test-bind_user_jsons.R +++ b/tests/testthat/test-bind_user_jsons.R @@ -1,6 +1,7 @@ ## context("bind_tweet_jsons") -empty_dir <- tempdir(check = TRUE) +empty_dir <- paste0(tempdir(), "/", paste0(sample(letters, 20), collapse = "")) +dir.create(empty_dir) my_cars <- mtcars my_cars$model <- rownames(my_cars) @@ -16,7 +17,9 @@ test_that("Expect sucess in binding two jsons", { }) unlink(empty_dir, recursive = TRUE) -temp_dir <- tempdir() + +temp_dir <- paste0(tempdir(), "/", paste0(sample(letters, 20), collapse = "")) +dir.create(temp_dir) test_that("Error on finding no jsons to bind", { expect_error(bind_tweet_jsons(temp_dir)) @@ -31,3 +34,4 @@ test_that("real data: data_path with trailing slash #97", { expect_error(bind_user_jsons("../testdata/commtwitter/"), NA) }) +unlink(temp_dir)