-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME.Rmd
158 lines (118 loc) · 4.03 KB
/
README.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# ChatStat
<!-- badges: start -->
<!-- badges: end -->
ChatStat is an R package to get data from online chat platforms, in tidy
formats. It currently only supports [Matrix](https://matrix.org), but more
backends are planned.
## Discussion
Come talk in
[#rmatrixstats:matrix.org](https://matrix.to/#/#rmatrixstats:matrix.org) to
discuss ChatStat or get help using it!
If you're new to R and are interested in learning more, you can join the [R
Matrix Space](https://matrix.to/#/#rlang:matrix.org) too!
## Installation
You can install the development version of ChatStat from
[GitHub](https://github.com/) with:
``` r
# install.packages("remotes")
remotes::install_github("GregSutcliffe/ChatStat")
```
If you're new to R, go with this approach:
``` bash
# install R from your package manager
(dnf / apt / pacman / etc) r
# make a working dir
mkdir chatstats && cd chatstats
# start r
R
```
```r
# virtual package environment
install.packages("renv")
renv::init()
# install ChatStat
install.packages("remotes")
remotes::install_github("GregSutcliffe/ChatStat")
```
Which will set up a new [renv](https://rstudio.github.io/renv/index.html)
environment with ChatStat installed and ready to use.
Because the report generation depends on a lot of packages, you may find this
takes a while!
## Usage
### Authentication
You will need your `access_token` and your homeserver URL, and optionally a port
if your homeserver is non-standard:
```r
# Authentication
Sys.setenv('token' = 'syt_foobarbaz',
'host' = 'matrix.org')
```
### Getting some room data
To retrieve room data initially, use `get_rooms()` like in the following
example.
```r
library(ChatStat)
room_ids <- c(
"!layMvdZSboJeKiyTAL:matrix.org", # #rmeta:matrix.org
"!FeFZUTDOtgIlOUoYhq:matrix.org", # #rstats:matrix.org
"!zSgZAViSMVQLIqRgOv:matrix.org" # #rmatrixstats:matrix.org
)
rooms <- get_rooms(room_ids, since = "2022-01-01")
```
This will store the result in `rooms` which we can take a look at:
```
> rooms
Matrix room state since 2022-01-01
Room ID Event count
!layMvdZSboJeKiyTAL:matrix.org 39
!FeFZUTDOtgIlOUoYhq:matrix.org 24
!zSgZAViSMVQLIqRgOv:matrix.org 186
```
And if we dig into the `rooms` object, we can get a table of the event data:
```
> rooms$events
# A tibble: 249 × 8
room id time type sender message_type body
<chr> <chr> <dttm> <chr> <chr> <chr> <chr>
1 !FeFZUTDOtg… $164… 2022-01-04 09:12:19 m.ro… @chri… m.text "If …
2 !FeFZUTDOtg… $164… 2022-01-04 12:04:28 m.re… @gwmn… NA NA
3 !FeFZUTDOtg… $164… 2022-01-04 18:38:00 m.re… @samf… NA NA
4 !FeFZUTDOtg… $164… 2022-01-10 13:07:21 m.re… @fede… NA NA
...
```
### Making a report
This is what you really came for! Once you have a `rooms` object, you can call:
```r
> ChatStat::render_report(rooms)
Output created: chatstat_report.html
```
This will create an HTML report in the current directory (or you can specify a
path), which will look something like:
<img src="man/figures/screenshot.png">
Obviously you can also do whatever you like with the raw data, see the
[Wiki](https://github.com/GregSutcliffe/ChatStat/wiki/A-non-R-user's-guide-to-ChatStat)
for an example of raw processing with `ggplot2`
### Saving / Loading
The `rooms` object can saved via `saveRDS(rooms,'./rooms.rds')` and loaded later
with `rooms <- readRDS('./rooms.rds')`.
### Updating
A rooms object that has been created using `get_rooms()` can be updated later
using `update_room()` which will add events that happened in the mean time.
```r
rooms_new <- update_rooms(rooms)
```
## Contributing
Contributions welcome! Please report issues as you find them, send pull requests
if you wish, or just come chat in the Matrix discussion room!