Skip to content

Commit d638d0b

Browse files
authored
Merge pull request #21 from kwathen/20-add-more-generic-files-for-trial-design-and-setup-with-createproject-funciton-KW
Updating project template files, moving code to the R directory for better organization
2 parents 0483095 + b4a5870 commit d638d0b

21 files changed

+1829
-928
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: OCTOPUS
22
Type: Package
33
Title: OCTOPUS
4-
Version: 1.3.0.9
4+
Version: 1.3.1
55
Author: J. Kyle Wathen
66
Maintainer: The package maintainer J. Kyle Wathen, PhD <kylewathen@gmail.com>
77
Authors@R: person("J. Kyle", "Wathen", email = "KyleWathen@gmail.com",

R/BuildSimulationResultsDataSet.R

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ BuildSimulationResultsDataSet <- function( )
2323
print( paste( "Combining main output files in the out subdirectory..." ) )
2424
simsMain <- CombineOutputFiles( "out" )
2525

26-
print( paste( ".....Saving combined main output as simsMain.RData"))
27-
save( simsMain, file = "simsMain.RData")
26+
print( paste( ".....Saving combined main output as simsMain.Rds"))
27+
#save( simsMain, file = "simsMain.RData")
28+
saveRDS( simsMain, file = "simsMain.Rds")
2829
simsCombined <- simsMain
2930
strISA <- "ISAOut1"
3031
iISA <- 1
@@ -38,12 +39,12 @@ BuildSimulationResultsDataSet <- function( )
3839

3940
#Save the object
4041
strObjName <- paste( "simsISA", iISA, sep="" )
41-
strFileName <- paste( strObjName, ".RData", sep="" )
42+
strFileName <- paste( strObjName, ".Rds", sep="" )
4243
print( paste( ".....Saving combined ISA", iISA, "output as", strFileName ) )
4344

4445
assign( strObjName, simsISA )
45-
save( list= strObjName, file= strFileName )
46-
46+
#save( list= strObjName, file= strFileName )
47+
saveRDS( simsISA, file= strFileName)
4748

4849
print( paste( "Merging main results with ISA ", iISA, " results...", sep="" ))
4950

@@ -54,7 +55,8 @@ BuildSimulationResultsDataSet <- function( )
5455
}
5556
simsCombined <- simsCombined[order( simsCombined$iScen),]
5657
print( paste( "Saving combined main and ISA output as simsCombined.RData" ) )
57-
save( simsCombined, file = "simsCombined.RData" )
58+
#save( simsCombined, file = "simsCombined.RData" )
59+
saveRDS( simsCombined, file = "simsCombined.Rds" )
5860
return( simsCombined )
5961

6062
}

R/CreateProject.R

+29-24
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ CreateProject <- function( strProjectDirectory = "",
4141
mQtyPatientsPerArm = NULL,
4242
dQtyMonthsFU = 1.0,
4343
vISAStartTimes = NULL,
44-
bCreateProjectSubdirectory = TRUE)
44+
bCreateProjectSubdirectory = TRUE,
45+
vPatientPerMonth = NULL)
4546
{
4647
strRet <- ""
4748

@@ -70,8 +71,8 @@ CreateProject <- function( strProjectDirectory = "",
7071
#Get the directory where OCTOPUS is installed
7172
strTemplateDirectory <- system.file("ProjectTemplate", package = strPackage)
7273

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 )
7576

7677
nCopySuccess <- sum( vResults )
7778
nCopyFail <- length( vResults ) - nCopySuccess
@@ -90,8 +91,8 @@ CreateProject <- function( strProjectDirectory = "",
9091
strSimOutRet <- ReplaceSimPatientOutcomeInfo( strNewProjectDirectory, strSimPatientOutcomeName )
9192

9293
#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 )
9596
# strBuildMeFile <- paste( strNewProjectDirectory, "/BuildMe.R", sep="" )
9697
# strTemplate <- readLines( strBuildMeFile )
9798
# strTemplate <- gsub( "TEMP_BORROWING", strBorrowing, strTemplate)
@@ -125,7 +126,7 @@ CreateProject <- function( strProjectDirectory = "",
125126
return( strRet )
126127
}
127128

128-
ReplaceBuildMeInfo <- function( strNewProjectDirectory, strFileName, mQtyPatientsPerArm, vISAStartTimes, strBorrowing, nQtyReps, dQtyMonthsFU )
129+
ReplaceBuildMeInfo <- function( strNewProjectDirectory, strFileName, mQtyPatientsPerArm, vISAStartTimes, strBorrowing, nQtyReps, dQtyMonthsFU, vPatientPerMonth )
129130
{
130131
#Replace options in the BuildMe.R file ####
131132
strBuildMeFile <- paste( strNewProjectDirectory, "/", strFileName, sep="" )
@@ -134,10 +135,14 @@ ReplaceBuildMeInfo <- function( strNewProjectDirectory, strFileName, mQtyPatien
134135
strTemplate <- gsub( "TEMP_QTY_REPS", nQtyReps, strTemplate )
135136
strTemplate <- gsub( "TMP_QTY_MONTHS_FU", dQtyMonthsFU, strTemplate )
136137

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 )
137142
if( is.null( mQtyPatientsPerArm ) == FALSE )
138143
{
139144

140-
strTemplate <- gsub( "TMP_MATRIX_DATA", paste( mQtyPatientsPerArm, collapse =","), strTemplate )
145+
strTemplate <- gsub( "TMP_MATRIX_DATA", paste( t(mQtyPatientsPerArm), collapse =","), strTemplate )
141146
strTemplate <- gsub( "TMP_NROW", nrow( mQtyPatientsPerArm ), strTemplate )
142147
strTemplate <- gsub( "TMP_NCOL", ncol( mQtyPatientsPerArm ), strTemplate )
143148
}
@@ -171,7 +176,7 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
171176
strTemplate <- gsub( "TEMP_ANALYSIS_MODEL", paste( strAnalysisName, sep=""), strTemplate)
172177
writeLines( strTemplate, con = strBuildMeFile )
173178

174-
strBuildMeFile <- paste( strProjectDirectory, "/RunParallelSimulations.R", sep="" )
179+
strBuildMeFile <- paste( strProjectDirectory, "/R/RunParallelSimulations.R", sep="" )
175180
strTemplate <- readLines( strBuildMeFile )
176181
strTemplate <- gsub( "TEMP_ANALYSIS_MODEL", paste( strAnalysisName, sep=""), strTemplate)
177182
writeLines( strTemplate, con = strBuildMeFile )
@@ -182,14 +187,14 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
182187
strRet <- paste( "The analysis you requested", strAnalysisName, "is not part of the OCTOPUS package. A file named" )
183188
strRet <- paste( "RunAnalysis.", strAnalysisName, ".R was created and the BuildMe.R set to source the new file.", sep="" )
184189

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 )
187192

188193
strTemplate <- readLines( strAnalysisFileName )
189194
strTemplate <- gsub( "TEMP_ANALYSIS_MODEL", paste( strAnalysisName, sep=""), strTemplate)
190195
writeLines( strTemplate, con = strAnalysisFileName )
191196

192-
strParallelSimulationsFileName <- paste( strProjectDirectory, "/RunParallelSimulations.R", sep="")
197+
strParallelSimulationsFileName <- paste( strProjectDirectory, "/R/RunParallelSimulations.R", sep="")
193198

194199
strTemplate <- readLines( strParallelSimulationsFileName )
195200
strTemplate <- gsub( "TEMP_ANALYSIS_MODEL", paste( strAnalysisName, sep=""), strTemplate)
@@ -204,22 +209,22 @@ ReplaceAnalysisInfo <- function( strProjectDirectory, strAnalysisName )
204209
strRet <- paste( strRet, " A new RunAnalysis function was NOT created.")
205210

206211

207-
file.remove( paste( strProjectDirectory, "/RunAnalysis.TEMP_ANALYSIS_MODEL.R", sep="") )
212+
file.remove( paste( strProjectDirectory, "/R/RunAnalysis.TEMP_ANALYSIS_MODEL.R", sep="") )
208213

209214
strBuildMeFile <- paste( strProjectDirectory, "/BuildMe.R", sep="" )
210215
strTemplate <- readLines( strBuildMeFile )
211-
strSouceCmd <- paste( "source\\( 'RunAnalysis.", strAnalysisName, ".R' \\)", sep = "")
216+
strSouceCmd <- paste( "source\\( 'R/RunAnalysis.", strAnalysisName, ".R' \\)", sep = "")
212217
strTemplate <- gsub( strSouceCmd, "", strTemplate)
213218
writeLines( strTemplate, con = strBuildMeFile )
214219

215220
strBuildMeFile <- paste( strProjectDirectory, "/BuildMeRunMultiCore.R", sep="" )
216221
strTemplate <- readLines( strBuildMeFile )
217-
strSouceCmd <- paste( "source\\( 'RunAnalysis.", strAnalysisName, ".R' \\)", sep = "")
222+
strSouceCmd <- paste( "source\\( 'R/RunAnalysis.", strAnalysisName, ".R' \\)", sep = "")
218223
strTemplate <- gsub( strSouceCmd, "", strTemplate)
219224
writeLines( strTemplate, con = strBuildMeFile )
220225

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 = "")
223228
strTemplate <- readLines( strParallelSimulationsFileName )
224229
strTemplate <- gsub( strSouceCmd, "", strTemplate)
225230
writeLines( strTemplate, con = strParallelSimulationsFileName )
@@ -249,7 +254,7 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
249254
writeLines( strTemplate, con = strBuildMeFile )
250255

251256

252-
strBuildMeFile <- paste( strProjectDirectory, "/RunParallelSimulations.R", sep="" )
257+
strBuildMeFile <- paste( strProjectDirectory, "/R/RunParallelSimulations.R", sep="" )
253258
strTemplate <- readLines( strBuildMeFile )
254259
strTemplate <- gsub( "TEMP_SIM_PATIENT_OUTCOME", paste( strSimPatientOutcomeName, sep=""), strTemplate)
255260
writeLines( strTemplate, con = strBuildMeFile )
@@ -260,8 +265,8 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
260265
strRet <- paste( "The patient simualator, SimPatientOutcomes", strSimPatientOutcomeName, "is not part of the OCTOPUS package. A file named" )
261266
strRet <- paste( "SimPatientOutcomes.", strSimPatientOutcomeName, ".R was created and the BuildMe.R set to source the new file.", sep="" )
262267

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 )
265270

266271
strTemplate <- readLines( strFileName )
267272
strTemplate <- gsub( "TEMP_SIM_PATIENT_OUTCOME", paste( strSimPatientOutcomeName, sep=""), strTemplate)
@@ -275,23 +280,23 @@ ReplaceSimPatientOutcomeInfo <- function( strProjectDirectory, strSimPatientOutc
275280
strRet <- paste( strRet, " A new SimPatientOutcomes function was NOT created.")
276281

277282
#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="") )
279284

280285
strBuildMeFile <- paste( strProjectDirectory, "/BuildMe.R", sep="" )
281286
strTemplate <- readLines( strBuildMeFile )
282-
strSouceCmd <- paste( "source\\( 'SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
287+
strSouceCmd <- paste( "source\\( 'R/SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
283288
strTemplate <- gsub( strSouceCmd, "", strTemplate)
284289
writeLines( strTemplate, con = strBuildMeFile )
285290

286291
strBuildMeFile <- paste( strProjectDirectory, "/BuildMeRunMultiCore.R", sep="" )
287292
strTemplate <- readLines( strBuildMeFile )
288-
strSouceCmd <- paste( "source\\( 'SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
293+
strSouceCmd <- paste( "source\\( 'R/SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
289294
strTemplate <- gsub( strSouceCmd, "", strTemplate)
290295
writeLines( strTemplate, con = strBuildMeFile )
291296

292-
strBuildMeFile <- paste( strProjectDirectory, "/RunParallelSimulations.R", sep="" )
297+
strBuildMeFile <- paste( strProjectDirectory, "/R/RunParallelSimulations.R", sep="" )
293298
strTemplate <- readLines( strBuildMeFile )
294-
strSouceCmd <- paste( "source\\( 'SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
299+
strSouceCmd <- paste( "source\\( 'R/SimPatientOutcomes.", strSimPatientOutcomeName, ".R' \\)", sep = "")
295300
strTemplate <- gsub( strSouceCmd, "", strTemplate)
296301
writeLines( strTemplate, con = strBuildMeFile )
297302
}

0 commit comments

Comments
 (0)