-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetaManagement.R
executable file
·184 lines (153 loc) · 7.36 KB
/
metaManagement.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# ------------------------------------------------------------------------------------
# Set the Environment:
# This code executes on build to ensure it exists in the MSToolkit library.
# This line sets the initial (empty) environment.
.ectdEnv <- new.env()
# This line sets the default "logging" file to "ectd.log"
assign("logfile", "ectd.log", envir = .ectdEnv)
# This line sets the default "verbose" behaviour, which determines the amount
# of logging performed. This is used, in particular, when errors are generated.
assign("verbose", FALSE, envir = .ectdEnv)
# This line sets the default data format (used for the format of data in the logging).
assign("dateFormat","%Y-%m-%d %H:%M:%OS4" , envir = .ectdEnv)
# This sets the current data storage method.
assign("dataStoreMethod", "CSV", envir = .ectdEnv)
# This sets the default column names
assign("colNames", list(
Subject = list(Name = "SUBJ", Other = "ID", Default = "SUBJ"),
Time = list(Name = "TIME", Other = c("DAY", "WEEK"), Default = "TIME"),
Dose = list(Name = "DOSE", Other = "", Default = "DOSE"),
Interim = list(Name = "INTERIM", Other = "", Default = "INTERIM"),
ParOmit = list(Name = "PAROMIT", Other = "", Default = "PAROMIT"),
RespOmit = list(Name = "RESPOMIT", Other = "", Default = "RESPOMIT"),
Response = list(Name = "RESP", Other = "DV", Default = "RESP"),
Trt = list(Name = "TRT", Other = "", Default = "TRT"),
Missing = list(Name = "MISSING", Other = "", Default = "MISSING"),
Replicate = list(Name = "Replicate", Other = "TRIAL", Default = "Replicate"),
DrugName = list(Name = "DRUGNAME", Other = "", Default = "DRUGNAME"),
Drug = list(Name = "DRUG", Other = "", Default = "DRUG")
),
envir = .ectdEnv
)
# The rest of this script sets the access functions for the meta layer.
# ------------------------------------------------------------------------------------
# Get or set the logfile.
getEctdLogFile <- function() {
get("logfile", envir = .ectdEnv)
}
setEctdLogFile <- function(file) {
if(missing(file)) {
ectdStop("Must provide log file.")
}
assign("logfile", file, envir = .ectdEnv )
invisible(file)
}
# Get or set the verbose.
getEctdVerbose <- function() get("verbose", envir = .ectdEnv)
setEctdVerbose <- function(verbose) {
if( missing(verbose) ) ectdStop("Must provide verbose flag")
assign("verbose", verbose, envir = .ectdEnv )
invisible(verbose)
}
# get or set the dateFormat
getEctdDateFormat <- function( ) get("dateFormat", envir = .ectdEnv)
setEctdDateFormat <- function(format){
if( missing(format) ) ectdStop("Date format must be provided")
assign("dateFormat", format, envir = .ectdEnv )
invisible(format)
}
# Get or set the data storage method.
getEctdDataMethod <- function() {
get("dataStoreMethod", envir = .ectdEnv)
}
setEctdDataMethod <- function(method) {
if(missing(method)) {
ectdStop("Must provide a data storage method: 'CSV', 'RData' or 'Internal'")
}
method <- match.arg(method, c("CSV", "RData", "Internal"))
assign("dataStoreMethod", method, envir = .ectdEnv )
invisible(method)
}
# Get & Set external execution path.
getEctdExternalPath <- function(pathName) {
getPaths <- get("externalPaths", envir = .ectdEnv)
if (missing(pathName)) {
return(names(getPaths))
}
else {
if (!is.character(pathName) || length(pathName) != 1) {
ectdStop("Single character value should be provided as the 'pathName' input.")
}
if (pathName %in% names(getPaths)) {
return(getPaths[pathName])
} else {
ectdStop(paste("Could not find external path '", pathName, "'", sep=""))
}
}
}
setEctdExternalPath <- function(pathName, Value) {
if (missing(pathName) || !is.character(pathName) || length(pathName) != 1) ectdStop("Single character value should be provided as the 'pathName' input")
if (missing(Value) || !is.character(Value) || length(Value) != 1) ectdStop("Single character value should be provided as the 'Value' input")
getPaths <- get("externalPaths", envir = .ectdEnv)
getPaths <- getPaths [ setdiff(names(getPaths), pathName) ]
getPaths <- c(getPaths, Value)
names(getPaths)[length(getPaths)] <- pathName
assign("externalPaths", getPaths, envir = .ectdEnv)
invisible(getPaths)
}
# Get, set and reset default column names
getEctdColName <- function(colName) {
if (missing(colName) || !is.character(colName) || length(colName) != 1) ectdStop("Single character value should be provided as the 'colName' input")
getNames <- get("colNames", envir = .ectdEnv)
if (colName %in% names(getNames)) return(getNames[[colName]]$Name)
else ectdStop(paste("Provided column name '", colName, "' cannot be found", sep=""))
}
setEctdColName <- function(colName, Value) {
if (missing(colName) || !is.character(colName) || length(colName) != 1) ectdStop("Single character value should be provided as the 'colName' input")
if (missing(Value) || !is.character(Value) || length(Value) != 1) ectdStop("Single character value should be provided as the 'Value' input")
getNames <- get("colNames", envir = .ectdEnv)
if (colName %in% names(getNames)) getNames[[colName]]$Name <- Value
else ectdStop(paste("Provided column name '", colName, "' not a valid column to set", sep=""))
assign("colNames", getNames, envir = .ectdEnv)
invisible(getNames)
}
resetEctdColNames <- function(whichNames=names(getNames)) {
getNames <- get("colNames", envir = .ectdEnv)
if (!is.character(whichNames)) {
ectdStop("Character vector should be provided as the 'whichNames' input")
}
whichNames <- whichNames[whichNames %in% names(getNames)]
if (length(whichNames)) {
for (i in whichNames) {
getNames[[i]]$Name <- getNames[[i]]$Default
}
}
assign("colNames", getNames, envir = .ectdEnv)
getNames
#invisible(getNames)
}
getEctdPossibleColNames <- function(colName) {
if (missing(colName) || !is.character(colName) || length(colName) != 1) ectdStop("Single character value should be provided as the 'colName' input")
getNames <- get("colNames", envir = .ectdEnv)
if (colName %in% names(getNames)) {
outVec <- unique(c(getNames[[colName]]$Name, getNames[[colName]]$Other))
return(setdiff(unique(outVec), ""))
}
else ectdStop(paste("Provided column '", colName, "' cannot be found", sep=""))
}
setEctdPossibleColNames <- function(colName, Value) {
if (missing(colName) || !is.character(colName) || length(colName) != 1) ectdStop("Single character value should be provided as the 'colName' input")
if (missing(Value) || !is.character(Value) || !length(Value)) ectdStop("A character vector of possible names must be provided")
getNames <- get("colNames", envir = .ectdEnv)
if (colName %in% names(getNames)) {
getNames[[colName]]$Other <- unique(Value)
assign("colNames", getNames, envir = .ectdEnv)
invisible(getNames)
}
else ectdStop(paste("Provided column '", colName, "' cannot be found", sep=""))
}
matchEctdColNames <- function(colName, dataNames) {
colList <- getEctdPossibleColNames(colName)
if (!any(myTest <- colList %in% dataNames)) return(NULL)
else colList[myTest][1]
}