-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsort_signifiers_v3.R
87 lines (76 loc) · 2.94 KB
/
sort_signifiers_v3.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
sigtypes <- function(data, unpack = c(TRUE, FALSE)) {
# Function to sort the signifiers into separate dataframes, according to type.
# Version 2.
stopifnot(!missing(data))
if (missing(unpack))
unpack <- FALSE
triads <- NULL
dyads <- NULL
stones <- NULL
questions <- NULL
descriptors <- NULL
respondents <- NULL
collector <- NULL
texts_org <- NULL
texts_eng <- NULL
titles_org <- NULL
titles_eng <- NULL
triads <- data[, grep("^T[1-9]", names(data))]
triads <- triads[, -grep(".X$|.Y$")]
dyads <- data[, grep("^D[1-9]", names(data))]
dyads <- dyads[, -grep(".X$|.Y$")]
stones <- data[, grep("^S[1-9]", names(data))]
questions <- data[, grep("^Q[1-9]", names(data))]
descriptors <- data[, grep("^DQ[1-9]", names(data))]
collector <- data[, grep("^C[1-9]", names(data))]
respondent <- data[, grep("^R[1-9]", names(data))]
# Texts and titles
if (match("texts_org", names(data), nomatch = FALSE)) {
texts_org <- data$texts_org
} else {
alt.names <- c("Your.experience", "FragmentEntry", "Describe.your.example.here")
if (match(alt.names, names(data), nomatch = FALSE)) {
texts_org <- data[, match(alt.names, names(data))]
} else {
cat(file = stderr(), "No texts found!")
}
}
if (match("texts_eng", names(data), nomatch = FALSE)) {
texts_eng <- data$texts_eng
} else {
alt.names <- c("English", "FragEntryEng")
if (match(alt.names, names(data), nomatch = FALSE))
texts_eng <- data[, match(alt.names, names(data))]
}
if (match("titles_org", names(data), nomatch = FALSE)) {
titles_org <- titles_org
} else {
alt.names <- c("StoryTitle", "Story.Title")
if (match(alt.names, names(data), nomatch = FALSE))
titles_org <- data[, match(alt.names, names(data))]
}
if (match("titles_eng", names(data), nomatch = FALSE)) {
titles_org <- titles_eng
} else {
alt.names <- "EngTitle"
if (match(alt.names, names(data), nomatch = FALSE))
titles_org <- data[, match(alt.names, names(data))]
}
# Aggregate objects
out <- list(triads, dyads, stones, questions, descriptors, respondents, collector, texts_org, texts_eng, titles_org, titles_eng)
if (unpack) {
assign("triads", triads, pos = parent.frame(n=1))
assign("dyads", dyads, pos = parent.frame(n=1))
assign("stones", stones, pos = parent.frame(n=1))
assign("questions", questions, pos = parent.frame(n=1))
assign("descriptors", descriptors, pos = parent.frame(n=1))
assign("respondent", respondent, pos = parent.frame(n=1))
assign("collector", collector, pos = parent.frame(n=1))
assign("texts_org", texts_org, pos = parent.frame(n=1))
assign("texts_eng", texts_eng, pos = parent.frame(n=1))
assign("titles_org", titles_org, pos = parent.frame(n=1))
assign("titles_eng", titles_eng, pos = parent.frame(n=1))
} else {
return(out)
}
}