-
Notifications
You must be signed in to change notification settings - Fork 0
/
3-reddit-chatgpt-collect-comments.Rmd
executable file
·70 lines (59 loc) · 1.54 KB
/
3-reddit-chatgpt-collect-comments.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
title: "Generative AI Generating Buzz: Volume, Engagement, and Content of Initial Reactions to ChatGPT in Discussions Across Education-Related Subreddits"
author: "Bret Staudt Willet"
date: "2023-04-04"
output: html_document
---
## Set Up
```{r setup}
knitr::opts_chunk$set(echo = TRUE)
library(tidyverse)
library(RedditExtractoR)
library(anytime)
library(lubridate)
library(beepr)
```
## Get Comments
```{r, message=FALSE}
posts2 <- read_csv("./data-gpt/!filtered-posts.csv")
```
```{r function, eval=FALSE}
subreddit_vector <- unique(posts2$subreddit)
comments_with_subreddit <-
function(x) {
tmp_comments <-
posts2 %>%
filter(subreddit == x) %>%
pull(post_url) %>%
RedditExtractoR::get_thread_content() %>%
`[[`(2)
if(is.data.frame(tmp_comments)) {
tmp_comments <-
tmp_comments %>%
mutate(subreddit = x,
comment_id = as.character(comment_id))
}
return(tmp_comments)
}
```
```{r get-comments, eval=FALSE}
comments_list <- list()
for(i in seq_along(subreddit_vector)) {
print(i)
comments_list[[i]] <- comments_with_subreddit(subreddit_vector[i])
}
beepr::beep(8)
```
```{r filter-comments, eval=FALSE}
all_comments <-
bind_rows(comments_list, .id = "column_label")
filtered_comments <-
all_comments %>%
filter(comment != "[deleted]",
comment!= "[removed]")
nrow(all_comments); nrow(filtered_comments)
```
```{r, eval=FALSE}
write_csv(all_comments, "./data-gpt/!all-comments.csv")
write_csv(filtered_comments, "./data-gpt/!filtered-comments.csv")
```