-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfdlabels.R
55 lines (41 loc) · 1.51 KB
/
fdlabels.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
fdlabels <- function(fdnames, nrep, nvar) {
# Extract plot labels and, if available, names for each replicate and
# each variable
# check fdnames, which must be a list object of length 3
if (!inherits(fdnames, "list"))
stop("Argument fdnames is not a list object.")
if (length(fdnames) != 3)
stop("Argument fdnames is not of length 3.")
# xlabel is fdnames[[1]] if it has length 1 and is not null
# otherwise xlabel is names(fdnames)[1]
xlabel = fdnames[[1]]
if (length(xlabel) > 1 || is.null(xlabel)) xlabel = names(fdnames)[1]
if (!is.character(xlabel)) xlabel = ""
# ylabel is fdnames[[3]] if it has length not equal to nvar and is not null
# otherwise ylabel is names(fdnames)[3]
ylabel = fdnames[[3]]
if ( (nvar > 1 && length(ylabel) == nvar) ||
is.null(ylabel)) ylabel = names(fdnames)[3]
if (length(ylabel) > 1) {
if (inherits(ylabel, "character")) ylabel = ylabel[1]
else {
if (inherits(ylabel, "list")) ylabel = ylabel[[1]]
else ylabel = ""
}
}
if (!is.character(ylabel)) ylabel = ""
# set up casenames
if (length(fdnames[[2]]) == nrep) {
casenames = as.character(fdnames[[2]])
} else {
casenames = NULL
}
# set up varnames
if (length(fdnames[[3]]) == nvar) {
varnames = as.character(fdnames[[3]])
} else {
varnames = NULL
}
return(list(xlabel=xlabel, ylabel=ylabel,
casenames=casenames, varnames=varnames))
}