Skip to content
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.

Commit

Permalink
Merge pull request #99 from chainsawriot/issue97
Browse files Browse the repository at this point in the history
fix #97
  • Loading branch information
cjbarrie authored Jun 7, 2021
2 parents 15ee561 + 7a16b18 commit 2ac945e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 32 deletions.
36 changes: 18 additions & 18 deletions R/bind_tweet_jsons.R
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand Down
11 changes: 1 addition & 10 deletions R/bind_user_jsons.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/testdata/commtwitter/data_1399005777138962433.json
Original file line number Diff line number Diff line change
@@ -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"}]
3 changes: 3 additions & 0 deletions tests/testdata/commtwitter/query
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#commtwitter
2021-05-30T00:00:00Z
2021-06-05T23:59:59Z
Loading

0 comments on commit 2ac945e

Please sign in to comment.