-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind_text.R
73 lines (54 loc) · 2.21 KB
/
find_text.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
library("stringr")
# retrieve path to all rmarkdown files
all.item.paths <- list.files(pattern = ".Rmd",
ignore.case = TRUE,
recursive = TRUE,
path = "SQRscripts",
full.names = TRUE)
n = length(all.item.paths)
# Words to find
words = c("[:blank:]\\!\\[", # 1
"[:blank:]$", # 2
"\\?[a-q]", # 3 find questionmark in string
"\\?\\?n", # 4
"pati\\?nten", # 5
"ge\\?nteresseerd", # 6
"correlatieco\\?ffici\\?nt", # 7
"richtingsco\\?ffici\\?nt", # 8
"be\\?nvloedt", # 9
"be\\?nvloed", # 10
"\\?meting", # 11
"\\?voor \\? \\?na", # 12
"\\?voor", # 13
"\\?na", # 14
"\\?D", # 15
"\\&\\#", # 16 Find HTML character encoding
"∪", # 17
"^NA$", # 18
"exextra\\[Type\\]\\:[:blank:]$", # 19
"taxonomyError", # 20
"^\\*[:blank:]\\*", # 21
"", # 22
"style", # 23
"exsolution: 0$", # 24
"" #25
)
word = 25
find = words[word]
find
stringi::stri_detect(str = text, regex = find)
# Work in progress, using stringr to find [
file = paste0("error-",word,".txt")
# Turn of creating new file to continue appending after crash
writeLines(paste("regex:", find), file)
for (i in 1:n) {
text <- readLines( all.item.paths[i] )
# Search for something in text and return line number
# Some useful key words: exsection Language Type Level
# Only show file if changes need to be made
if( sum(stringi::stri_detect(str = text, regex = find) ) > 0 ) {
line.nr = stringi::stri_detect(str = text, regex = find)
print(c(i, text[line.nr], all.item.paths[i]) )
write(paste0(i, ' open "', all.item.paths[i], '"'), file, append = TRUE)
}
}