-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnonimysation.R
85 lines (61 loc) · 2.38 KB
/
Anonimysation.R
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
# Introduction----------------
# Project: GreveDosApps
# File: Anonimysation.R
# Objective: Functions for creating anonymous twitter handles
# Researcher: rll307
# Date: 10/02/22 - 18:37:19
# Information----------
writeLines(
"**Portuguese**:
Este script foi desenvolvido como forma de auxiliar colegas da área de LC.
Se você quiser discutir outras aplicações, por favor, me escreva:
Contato: Rodrigo Esteves de Lima-Lopes
Outros scripts: http://www.iel.unicamp.br")
writeLines (
"**English**:
This script was developed as a way to assist colleagues in the LC area.
If you need more information or would like to discuss further applications,
please, drop me a line:
Contact: Rodrigo Esteves de Lima-Lopes
Other scripts: http://www.iel.unicamp.br ")
# Packages ----------------------------------------------------------------
library(stringr)
library(digest)
library(stringi)
# Functions ---------------------------------------------------------------
source('Functions.R')
# Step 1 ------------------------------------------------------------------
# Get the names from the screename column
users.1 <- Strike$screen_name
users.1 <- unique(users.1)
# Step 2 ------------------------------------------------------------------
# Gets screenames from text
users.1.2 <- screenames(Strike$text)
users.1.2 <- unique(users.1.2)
# join them all
users <- c(users.1,users.1.2) |>
unique()
users <-users |>
data.frame()
# step 3 ------------------------------------------------------------------
# Creating a data frame with columns oldname and new name
users$new.name <- hashed_id(users$users, "YourSaltHere")
#Creating a column with @ for the body of the tweets
users$original <- paste0(rep("@", length(users$users)), users$users)
# Step 4 -----------------------------------------------------------------
#Making the actual substitution
#From the column screename
Strike$screen_name <-
stri_replace_all_fixed(str = Strike$screen_name,
pattern = users$users,
replacement = users$new.name,
vectorize_all = FALSE)
#from the text
Strike$text <-
stri_replace_all_fixed(str = Strike$screen_name,
pattern = users$original,
replacement = users$new.name,
vectorize_all = FALSE)
#Anonimisation is done