|
1 | 1 | `addBaselineMatrices` <- |
2 | 2 | function(state, |
3 | 3 | year, |
4 | | - add.matrices.to.which.state=NULL) { |
| 4 | + add.matrices.to.which.state=NULL, |
| 5 | + SGPt = FALSE) { |
5 | 6 |
|
6 | 7 | SGPstateData <- SGP::SGPstateData ### Needed due to assignment of values to SGPstateData |
7 | 8 |
|
8 | 9 | ### Utility function |
9 | | - getMatrixLabel <- function(state, year, add.matrices.to.which.state) { |
| 10 | + getMatrixLabel <- function(state, year, add.matrices.to.which.state, SGPt) { |
10 | 11 | if (!paste(state, "Baseline_Matrices", sep="_") %in% names(SGPmatrices::SGPmatrices)) { |
11 | 12 | stop(paste("\tNOTE: Baseline matrices for state:", state, "not in SGPmatrices. Contact package maintainer to have baseline matrices added to package.")) |
12 | 13 | } |
13 | 14 | tmp.years <- names(SGPmatrices::SGPmatrices[[paste(state, "Baseline_Matrices", sep="_")]]) |
14 | 15 | if (year < sort(tmp.years)[1]) stop("NOTE: Supplied year precedes years associated with baseline matrices in package. Contact package developer if you think this is in error.") |
15 | 16 | if (!year %in% tmp.years) year <- tmp.years[which(year==sort(c(tmp.years, year)))-1L] |
16 | | - matrix.label <- paste0("SGPmatrices::SGPmatrices[['", paste(state, "Baseline_Matrices", sep="_"), "']][['", year, "']]") |
17 | | - message(paste0("\tNOTE: Adding ", SGP::getStateAbbreviation(state, type="Long"), " (", state, ") ", year, " baseline matrices to SGPstateData for state ", |
| 17 | + if (!SGPt) { |
| 18 | + matrix.label <- paste0("SGPmatrices::SGPmatrices[['", paste(state, "Baseline_Matrices", sep="_"), "']][['", year, "']]") |
| 19 | + message(paste0("\tNOTE: Adding ", SGP::getStateAbbreviation(state, type="Long"), " (", state, ") ", year, " baseline matrices to SGPstateData for state ", |
18 | 20 | add.matrices.to.which.state)) |
| 21 | + } else { |
| 22 | + matrix.label <- paste0("SGPmatrices::SGPmatrices[['", paste(state, "SGPt_Baseline_Matrices", sep="_"), "']][['", year, "']]") |
| 23 | + message(paste0("\tNOTE: Adding ", SGP::getStateAbbreviation(state, type="Long"), " (", state, ") ", year, " SGPt baseline matrices to SGPstateData for state ", |
| 24 | + add.matrices.to.which.state)) |
| 25 | + } |
19 | 26 | return(matrix.label) |
20 | 27 | } |
21 | 28 |
|
22 | 29 | if (is.null(add.matrices.to.which.state)) add.matrices.to.which.state <- state |
23 | 30 |
|
24 | | - SGPstateData[[add.matrices.to.which.state]][["Baseline_splineMatrix"]][["Coefficient_Matrices"]] <- eval(parse(text=getMatrixLabel(state, year, add.matrices.to.which.state))) |
| 31 | + SGPstateData[[add.matrices.to.which.state]][["Baseline_splineMatrix"]][["Coefficient_Matrices"]] <- eval(parse(text=getMatrixLabel(state, year, add.matrices.to.which.state, SGPt))) |
25 | 32 | return(SGPstateData) |
26 | 33 | } ### END addBaselineMatrices |
0 commit comments