@@ -41,7 +41,8 @@ CreateProject <- function( strProjectDirectory = "",
41
41
mQtyPatientsPerArm = NULL ,
42
42
dQtyMonthsFU = 1.0 ,
43
43
vISAStartTimes = NULL ,
44
- bCreateProjectSubdirectory = TRUE )
44
+ bCreateProjectSubdirectory = TRUE ,
45
+ vPatientPerMonth = NULL )
45
46
{
46
47
strRet <- " "
47
48
@@ -70,8 +71,8 @@ CreateProject <- function( strProjectDirectory = "",
70
71
# Get the directory where OCTOPUS is installed
71
72
strTemplateDirectory <- system.file(" ProjectTemplate" , package = strPackage )
72
73
73
- vFilesToCopy <- list.files( strTemplateDirectory )
74
- vResults <- file.copy( file.path(strTemplateDirectory , vFilesToCopy ), strNewProjectDirectory )
74
+ vFilesToCopy <- list.files( strTemplateDirectory , recursive = FALSE , include.dirs = TRUE )
75
+ vResults <- file.copy( file.path(strTemplateDirectory , vFilesToCopy ), strNewProjectDirectory , recursive = TRUE )
75
76
76
77
nCopySuccess <- sum( vResults )
77
78
nCopyFail <- length( vResults ) - nCopySuccess
@@ -90,8 +91,8 @@ CreateProject <- function( strProjectDirectory = "",
90
91
strSimOutRet <- ReplaceSimPatientOutcomeInfo( strNewProjectDirectory , strSimPatientOutcomeName )
91
92
92
93
# Replace options in the BuildMe.R file ####
93
- ReplaceBuildMeInfo( strNewProjectDirectory , " BuildMe.R" , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU )
94
- ReplaceBuildMeInfo( strNewProjectDirectory , " BuildMeRunMultiCore.R" , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU )
94
+ ReplaceBuildMeInfo( strNewProjectDirectory , " BuildMe.R" , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU , vPatientPerMonth )
95
+ ReplaceBuildMeInfo( strNewProjectDirectory , " BuildMeRunMultiCore.R" , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU , vPatientPerMonth )
95
96
# strBuildMeFile <- paste( strNewProjectDirectory, "/BuildMe.R", sep="" )
96
97
# strTemplate <- readLines( strBuildMeFile )
97
98
# strTemplate <- gsub( "TEMP_BORROWING", strBorrowing, strTemplate)
@@ -125,7 +126,7 @@ CreateProject <- function( strProjectDirectory = "",
125
126
return ( strRet )
126
127
}
127
128
128
- ReplaceBuildMeInfo <- function ( strNewProjectDirectory , strFileName , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU )
129
+ ReplaceBuildMeInfo <- function ( strNewProjectDirectory , strFileName , mQtyPatientsPerArm , vISAStartTimes , strBorrowing , nQtyReps , dQtyMonthsFU , vPatientPerMonth )
129
130
{
130
131
# Replace options in the BuildMe.R file ####
131
132
strBuildMeFile <- paste( strNewProjectDirectory , " /" , strFileName , sep = " " )
@@ -134,10 +135,14 @@ ReplaceBuildMeInfo <- function( strNewProjectDirectory, strFileName, mQtyPatien
134
135
strTemplate <- gsub( " TEMP_QTY_REPS" , nQtyReps , strTemplate )
135
136
strTemplate <- gsub( " TMP_QTY_MONTHS_FU" , dQtyMonthsFU , strTemplate )
136
137
138
+ if ( ! is.null(vPatientPerMonth ))
139
+ strTemplate <- gsub( " TEMP_PATIENTS_PER_MONTH" , paste0( " c( " , paste( vPatientPerMonth , collapse = " , " ), " )" ), strTemplate )
140
+ else
141
+ strTemplate <- gsub( " TEMP_PATIENTS_PER_MONTH" , " NULL" , strTemplate )
137
142
if ( is.null( mQtyPatientsPerArm ) == FALSE )
138
143
{
139
144
140
- strTemplate <- gsub( " TMP_MATRIX_DATA" , paste( mQtyPatientsPerArm , collapse = " ," ), strTemplate )
145
+ strTemplate <- gsub( " TMP_MATRIX_DATA" , paste( t( mQtyPatientsPerArm ) , collapse = " ," ), strTemplate )
141
146
strTemplate <- gsub( " TMP_NROW" , nrow( mQtyPatientsPerArm ), strTemplate )
142
147
strTemplate <- gsub( " TMP_NCOL" , ncol( mQtyPatientsPerArm ), strTemplate )
143
148
}
@@ -171,7 +176,7 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
171
176
strTemplate <- gsub( " TEMP_ANALYSIS_MODEL" , paste( strAnalysisName , sep = " " ), strTemplate )
172
177
writeLines( strTemplate , con = strBuildMeFile )
173
178
174
- strBuildMeFile <- paste( strProjectDirectory , " /RunParallelSimulations.R" , sep = " " )
179
+ strBuildMeFile <- paste( strProjectDirectory , " /R/ RunParallelSimulations.R" , sep = " " )
175
180
strTemplate <- readLines( strBuildMeFile )
176
181
strTemplate <- gsub( " TEMP_ANALYSIS_MODEL" , paste( strAnalysisName , sep = " " ), strTemplate )
177
182
writeLines( strTemplate , con = strBuildMeFile )
@@ -182,14 +187,14 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
182
187
strRet <- paste( " The analysis you requested" , strAnalysisName , " is not part of the OCTOPUS package. A file named" )
183
188
strRet <- paste( " RunAnalysis." , strAnalysisName , " .R was created and the BuildMe.R set to source the new file." , sep = " " )
184
189
185
- strAnalysisFileName <- paste( strProjectDirectory , " /RunAnalysis." , strAnalysisName , " .R" , sep = " " )
186
- file.rename( paste( strProjectDirectory , " /RunAnalysis.TEMP_ANALYSIS_MODEL.R" , sep = " " ), strAnalysisFileName )
190
+ strAnalysisFileName <- paste( strProjectDirectory , " /R/ RunAnalysis." , strAnalysisName , " .R" , sep = " " )
191
+ file.rename( paste( strProjectDirectory , " /R/ RunAnalysis.TEMP_ANALYSIS_MODEL.R" , sep = " " ), strAnalysisFileName )
187
192
188
193
strTemplate <- readLines( strAnalysisFileName )
189
194
strTemplate <- gsub( " TEMP_ANALYSIS_MODEL" , paste( strAnalysisName , sep = " " ), strTemplate )
190
195
writeLines( strTemplate , con = strAnalysisFileName )
191
196
192
- strParallelSimulationsFileName <- paste( strProjectDirectory , " /RunParallelSimulations.R" , sep = " " )
197
+ strParallelSimulationsFileName <- paste( strProjectDirectory , " /R/ RunParallelSimulations.R" , sep = " " )
193
198
194
199
strTemplate <- readLines( strParallelSimulationsFileName )
195
200
strTemplate <- gsub( " TEMP_ANALYSIS_MODEL" , paste( strAnalysisName , sep = " " ), strTemplate )
@@ -204,22 +209,22 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
204
209
strRet <- paste( strRet , " A new RunAnalysis function was NOT created." )
205
210
206
211
207
- file.remove( paste( strProjectDirectory , " /RunAnalysis.TEMP_ANALYSIS_MODEL.R" , sep = " " ) )
212
+ file.remove( paste( strProjectDirectory , " /R/ RunAnalysis.TEMP_ANALYSIS_MODEL.R" , sep = " " ) )
208
213
209
214
strBuildMeFile <- paste( strProjectDirectory , " /BuildMe.R" , sep = " " )
210
215
strTemplate <- readLines( strBuildMeFile )
211
- strSouceCmd <- paste( " source\\ ( 'RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
216
+ strSouceCmd <- paste( " source\\ ( 'R/ RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
212
217
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
213
218
writeLines( strTemplate , con = strBuildMeFile )
214
219
215
220
strBuildMeFile <- paste( strProjectDirectory , " /BuildMeRunMultiCore.R" , sep = " " )
216
221
strTemplate <- readLines( strBuildMeFile )
217
- strSouceCmd <- paste( " source\\ ( 'RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
222
+ strSouceCmd <- paste( " source\\ ( 'R/ RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
218
223
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
219
224
writeLines( strTemplate , con = strBuildMeFile )
220
225
221
- strParallelSimulationsFileName <- paste( strProjectDirectory , " /RunParallelSimulations.R" , sep = " " )
222
- strSouceCmd <- paste( " source\\ ( 'RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
226
+ strParallelSimulationsFileName <- paste( strProjectDirectory , " /R/ RunParallelSimulations.R" , sep = " " )
227
+ strSouceCmd <- paste( " source\\ ( 'R/ RunAnalysis." , strAnalysisName , " .R' \\ )" , sep = " " )
223
228
strTemplate <- readLines( strParallelSimulationsFileName )
224
229
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
225
230
writeLines( strTemplate , con = strParallelSimulationsFileName )
@@ -249,7 +254,7 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
249
254
writeLines( strTemplate , con = strBuildMeFile )
250
255
251
256
252
- strBuildMeFile <- paste( strProjectDirectory , " /RunParallelSimulations.R" , sep = " " )
257
+ strBuildMeFile <- paste( strProjectDirectory , " /R/ RunParallelSimulations.R" , sep = " " )
253
258
strTemplate <- readLines( strBuildMeFile )
254
259
strTemplate <- gsub( " TEMP_SIM_PATIENT_OUTCOME" , paste( strSimPatientOutcomeName , sep = " " ), strTemplate )
255
260
writeLines( strTemplate , con = strBuildMeFile )
@@ -260,8 +265,8 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
260
265
strRet <- paste( " The patient simualator, SimPatientOutcomes" , strSimPatientOutcomeName , " is not part of the OCTOPUS package. A file named" )
261
266
strRet <- paste( " SimPatientOutcomes." , strSimPatientOutcomeName , " .R was created and the BuildMe.R set to source the new file." , sep = " " )
262
267
263
- strFileName <- paste( strProjectDirectory , " /SimPatientOutcomes." , strSimPatientOutcomeName , " .R" , sep = " " )
264
- file.rename( paste( strProjectDirectory , " /SimPatientOutcomes.TEMP_SIM_PATIENT_OUTCOME.R" , sep = " " ), strFileName )
268
+ strFileName <- paste( strProjectDirectory , " /R/ SimPatientOutcomes." , strSimPatientOutcomeName , " .R" , sep = " " )
269
+ file.rename( paste( strProjectDirectory , " /R/ SimPatientOutcomes.TEMP_SIM_PATIENT_OUTCOME.R" , sep = " " ), strFileName )
265
270
266
271
strTemplate <- readLines( strFileName )
267
272
strTemplate <- gsub( " TEMP_SIM_PATIENT_OUTCOME" , paste( strSimPatientOutcomeName , sep = " " ), strTemplate )
@@ -275,23 +280,23 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
275
280
strRet <- paste( strRet , " A new SimPatientOutcomes function was NOT created." )
276
281
277
282
# The SimPatientOutcome method exists, need to delete the file name and remove the source command for it from the BuildMe
278
- file.remove( paste( strProjectDirectory , " /SimPatientOutcomes.TEMP_SIM_PATIENT_OUTCOME.R" , sep = " " ) )
283
+ file.remove( paste( strProjectDirectory , " /R/ SimPatientOutcomes.TEMP_SIM_PATIENT_OUTCOME.R" , sep = " " ) )
279
284
280
285
strBuildMeFile <- paste( strProjectDirectory , " /BuildMe.R" , sep = " " )
281
286
strTemplate <- readLines( strBuildMeFile )
282
- strSouceCmd <- paste( " source\\ ( 'SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
287
+ strSouceCmd <- paste( " source\\ ( 'R/ SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
283
288
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
284
289
writeLines( strTemplate , con = strBuildMeFile )
285
290
286
291
strBuildMeFile <- paste( strProjectDirectory , " /BuildMeRunMultiCore.R" , sep = " " )
287
292
strTemplate <- readLines( strBuildMeFile )
288
- strSouceCmd <- paste( " source\\ ( 'SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
293
+ strSouceCmd <- paste( " source\\ ( 'R/ SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
289
294
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
290
295
writeLines( strTemplate , con = strBuildMeFile )
291
296
292
- strBuildMeFile <- paste( strProjectDirectory , " /RunParallelSimulations.R" , sep = " " )
297
+ strBuildMeFile <- paste( strProjectDirectory , " /R/ RunParallelSimulations.R" , sep = " " )
293
298
strTemplate <- readLines( strBuildMeFile )
294
- strSouceCmd <- paste( " source\\ ( 'SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
299
+ strSouceCmd <- paste( " source\\ ( 'R/ SimPatientOutcomes." , strSimPatientOutcomeName , " .R' \\ )" , sep = " " )
295
300
strTemplate <- gsub( strSouceCmd , " " , strTemplate )
296
301
writeLines( strTemplate , con = strBuildMeFile )
297
302
}
0 commit comments