Skip to content

Commit d3b7a6a

Browse files
bug fixes: else if, whitespace, duplicates in table
1 parent 652baa5 commit d3b7a6a

File tree

1 file changed

+65
-35
lines changed

1 file changed

+65
-35
lines changed

R/get_blocks.R

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ get_block_input <- function(ctl0 = NULL, ext0 = NULL){
1313

1414
note1 <- " /* NOTE: Parameter identified as time-varying. A full dataset must be supplied to mrgsolve or the parameter should instead be calculated in $ODE. */"
1515
note2 <- " /* NOTE: Parameter identified as time-varying. Please refer to TIME, self.time(), and SOLVERTIME if TSFD is equivalent to TIME. */"
16-
note3 <- " /* NOTE: Parameter identified as time-varying. Please refer to self.tad(). */"
16+
note3 <- " /* NOTE: Parameter identified as time-varying. Please refer to self.tad() and mrg::tadose. */"
1717
note4 <- " /* NOTE: Parameter identified as related to AMT. Please refer to self.amt() or supply in the dataset. */"
1818

1919
input <- ctl0 %>%
@@ -120,24 +120,71 @@ get_block_pk <- function(ctl0 = NULL, mrg_code = NULL, cmts = NULL){
120120
input <- ctl0 %>%
121121
dplyr::filter((BLOCK == "PK" | BLOCK == "DES"), FLG_BLOCK != 1)%>%
122122
dplyr::select(V1,BLOCK)%>%
123+
123124
dplyr::mutate(V1 = gsub("EXP\\(","exp\\(",V1))%>% # convert to mrgsolve syntax
124125
dplyr::mutate(V1 = gsub("LOG\\(","log\\(",V1))%>%
125126
dplyr::mutate(V1 = gsub("LOG10\\(","log10\\(",V1))%>%
126127
dplyr::mutate(V1 = gsub("SQRT\\(","sqrt\\(",V1))%>%
128+
129+
dplyr::mutate(V1 = gsub("\\s*ELSE\\s*IF\\s*\\(\\s*", "}else if\\(",V1))%>% # 06aug2024 changed all \\s to \\s* in this code header section; put call w/ most whitespace replacement first
130+
dplyr::mutate(V1 = gsub("\\s*ELSE\\s*IF\\s*\\(", "}else if\\(",V1))%>% # 06aug2024
131+
dplyr::mutate(V1 = gsub("ELSE\\s*IF\\s*\\(\\s*", "}else if\\(",V1))%>% # 06aug2024
132+
dplyr::mutate(V1 = gsub("ELSE\\s*IF\\s*\\(", "}else if\\(",V1))%>% # 06aug2024
133+
dplyr::mutate(V1 = gsub("\\s*ELSE\\s*IF\\(\\s*", "}else if\\(",V1))%>% # 06aug2024
134+
dplyr::mutate(V1 = gsub("\\s*ELSE\\s*IF\\(", "}else if\\(",V1))%>% # 06aug2024
135+
dplyr::mutate(V1 = gsub("ELSE\\s*IF\\(\\s*", "}else if\\(",V1))%>% # 06aug2024
136+
dplyr::mutate(V1 = gsub("ELSE\\s*IF\\(", "}else if\\(",V1))%>% # 06aug2024
137+
138+
dplyr::mutate(V1 = gsub("\\s*IF\\s*\\(\\s*","if\\(",V1))%>% # 06aug2024
139+
dplyr::mutate(V1 = gsub("\\s*IF\\s*\\(","if\\(",V1))%>% # 06aug2024
140+
dplyr::mutate(V1 = gsub("IF\\s*\\(\\s*","if\\(",V1))%>% # 06aug2024
141+
dplyr::mutate(V1 = gsub("IF\\s*\\(","if\\(",V1))%>%
142+
dplyr::mutate(V1 = gsub("\\s*IF\\(\\s*","if\\(",V1))%>% # 06aug2024
143+
dplyr::mutate(V1 = gsub("\\s*IF\\(","if\\(",V1))%>% # 06aug2024
144+
dplyr::mutate(V1 = gsub("IF\\(\\s*","if\\(",V1))%>% # 06aug2024
127145
dplyr::mutate(V1 = gsub("IF\\(","if\\(",V1))%>%
128-
dplyr::mutate(V1 = gsub("IF\\s\\(","if\\(",V1))%>%
146+
147+
dplyr::mutate(V1 = gsub("\\s*ELSE\\s*","}else{",V1))%>% # 06aug2024
148+
dplyr::mutate(V1 = gsub("\\s*ELSE","}else{",V1))%>% # 06aug2024
149+
dplyr::mutate(V1 = gsub("ELSE\\s*","}else{",V1))%>% # 06aug2024
129150
dplyr::mutate(V1 = gsub("ELSE","}else{",V1))%>%
151+
152+
dplyr::mutate(V1 = gsub("\\s*THEN\\s*","\\{",V1))%>% # 06aug2024
153+
dplyr::mutate(V1 = gsub("\\s*THEN","\\{",V1))%>% # 06aug2024
154+
dplyr::mutate(V1 = gsub("THEN\\s*","\\{",V1))%>% # 06aug2024
130155
dplyr::mutate(V1 = gsub("THEN","\\{",V1))%>%
156+
157+
dplyr::mutate(V1 = gsub("\\s*ENDIF\\s*","\\}",V1))%>% #06aug2024
158+
dplyr::mutate(V1 = gsub("\\s*ENDIF","\\}",V1))%>% #06aug2024
159+
dplyr::mutate(V1 = gsub("ENDIF\\s*","\\}",V1))%>% #06aug2024
131160
dplyr::mutate(V1 = gsub("ENDIF","\\}",V1))%>%
132161

133-
dplyr::mutate(V1 = gsub("\\s\\.EQ\\.\\s","==",V1))%>%
134-
dplyr::mutate(V1 = gsub("\\s\\.NE\\.\\s","!=",V1))%>%
135-
dplyr::mutate(V1 = gsub("\\s\\.GT\\.\\s",">",V1))%>%
136-
dplyr::mutate(V1 = gsub("\\s\\.LT\\.\\s","<",V1))%>%
137-
dplyr::mutate(V1 = gsub("\\s\\.GE\\.\\s",">=",V1))%>%
138-
dplyr::mutate(V1 = gsub("\\s\\.LE\\.\\s","<=",V1))%>%
139-
dplyr::mutate(V1 = gsub("\\s\\.AND\\.\\s","\\&",V1))%>%
140-
dplyr::mutate(V1 = gsub("\\s\\.OR\\.\\s","\\|",V1))%>%
162+
dplyr::mutate(V1 = gsub("\\s*\\.EQ\\.\\s*","==",V1))%>%
163+
dplyr::mutate(V1 = gsub("\\s*\\.NE\\.\\s*","!=",V1))%>%
164+
dplyr::mutate(V1 = gsub("\\s*\\.GT\\.\\s*",">",V1))%>%
165+
dplyr::mutate(V1 = gsub("\\s*\\.LT\\.\\s*","<",V1))%>%
166+
dplyr::mutate(V1 = gsub("\\s*\\.GE\\.\\s*",">=",V1))%>%
167+
dplyr::mutate(V1 = gsub("\\s*\\.LE\\.\\s*","<=",V1))%>%
168+
dplyr::mutate(V1 = gsub("\\s*\\.AND\\.\\s*","\\&",V1))%>%
169+
dplyr::mutate(V1 = gsub("\\s*\\.OR\\.\\s*","\\|",V1))%>%
170+
171+
dplyr::mutate(V1 = gsub("\\.EQ\\.\\s*","==",V1))%>%
172+
dplyr::mutate(V1 = gsub("\\.NE\\.\\s*","!=",V1))%>%
173+
dplyr::mutate(V1 = gsub("\\.GT\\.\\s*",">",V1))%>%
174+
dplyr::mutate(V1 = gsub("\\.LT\\.\\s*","<",V1))%>%
175+
dplyr::mutate(V1 = gsub("\\.GE\\.\\s*",">=",V1))%>%
176+
dplyr::mutate(V1 = gsub("\\.LE\\.\\s*","<=",V1))%>%
177+
dplyr::mutate(V1 = gsub("\\.AND\\.\\s*","\\&",V1))%>%
178+
dplyr::mutate(V1 = gsub("\\.OR\\.\\s*","\\|",V1))%>%
179+
180+
dplyr::mutate(V1 = gsub("\\s*\\.EQ\\.","==",V1))%>%
181+
dplyr::mutate(V1 = gsub("\\s*\\.NE\\.","!=",V1))%>%
182+
dplyr::mutate(V1 = gsub("\\s*\\.GT\\.",">",V1))%>%
183+
dplyr::mutate(V1 = gsub("\\s*\\.LT\\.","<",V1))%>%
184+
dplyr::mutate(V1 = gsub("\\s*\\.GE\\.",">=",V1))%>%
185+
dplyr::mutate(V1 = gsub("\\s*\\.LE\\.","<=",V1))%>%
186+
dplyr::mutate(V1 = gsub("\\s*\\.AND\\.","\\&",V1))%>%
187+
dplyr::mutate(V1 = gsub("\\s*\\.OR\\.","\\|",V1))%>%
141188

142189
dplyr::mutate(V1 = gsub("\\.EQ\\.","==",V1))%>%
143190
dplyr::mutate(V1 = gsub("\\.NE\\.","!=",V1))%>%
@@ -146,25 +193,7 @@ get_block_pk <- function(ctl0 = NULL, mrg_code = NULL, cmts = NULL){
146193
dplyr::mutate(V1 = gsub("\\.GE\\.",">=",V1))%>%
147194
dplyr::mutate(V1 = gsub("\\.LE\\.","<=",V1))%>%
148195
dplyr::mutate(V1 = gsub("\\.AND\\.","\\&",V1))%>%
149-
dplyr::mutate(V1 = gsub("\\.OR\\.","\\|",V1))%>%
150-
151-
dplyr::mutate(V1 = gsub("\\.EQ\\.\\s","==",V1))%>%
152-
dplyr::mutate(V1 = gsub("\\.NE\\.\\s","!=",V1))%>%
153-
dplyr::mutate(V1 = gsub("\\.GT\\.\\s",">",V1))%>%
154-
dplyr::mutate(V1 = gsub("\\.LT\\.\\s","<",V1))%>%
155-
dplyr::mutate(V1 = gsub("\\.GE\\.\\s",">=",V1))%>%
156-
dplyr::mutate(V1 = gsub("\\.LE\\.\\s","<=",V1))%>%
157-
dplyr::mutate(V1 = gsub("\\.AND\\.\\s","\\&",V1))%>%
158-
dplyr::mutate(V1 = gsub("\\.OR\\.\\s","\\|",V1))%>%
159-
160-
dplyr::mutate(V1 = gsub("\\s\\.EQ\\.","==",V1))%>%
161-
dplyr::mutate(V1 = gsub("\\s\\.NE\\.","!=",V1))%>%
162-
dplyr::mutate(V1 = gsub("\\s\\.GT\\.",">",V1))%>%
163-
dplyr::mutate(V1 = gsub("\\s\\.LT\\.","<",V1))%>%
164-
dplyr::mutate(V1 = gsub("\\s\\.GE\\.",">=",V1))%>%
165-
dplyr::mutate(V1 = gsub("\\s\\.LE\\.","<=",V1))%>%
166-
dplyr::mutate(V1 = gsub("\\s\\.AND\\.","\\&",V1))%>%
167-
dplyr::mutate(V1 = gsub("\\s\\.OR\\.","\\|",V1))
196+
dplyr::mutate(V1 = gsub("\\.OR\\.","\\|",V1))
168197

169198
### Flag Conditional Statements ####
170199

@@ -187,9 +216,9 @@ get_block_pk <- function(ctl0 = NULL, mrg_code = NULL, cmts = NULL){
187216

188217
tmp <- input %>%
189218
dplyr::filter(FLG_COND2 == 1)%>%
190-
dplyr::mutate(V1 = gsub("\\s", "", V1))%>% # remove all white space from single line conditional statements
191-
dplyr::mutate(V1 = gsub("\\{", "", V1))%>% # remove { from single line conditional statements
192-
dplyr::mutate(V1 = gsub("\\}", "", V1)) # remove } from single line conditional statements
219+
dplyr::mutate(V1 = gsub("\\s*", "", V1))%>% # remove all white space from single line conditional statements; 06aug2024 changed //s to //s*
220+
dplyr::mutate(V1 = gsub("\\{", "", V1))%>% # remove { from single line conditional statements
221+
dplyr::mutate(V1 = gsub("\\}", "", V1)) # remove } from single line conditional statements
193222

194223
if(nrow(tmp)>0){
195224

@@ -351,7 +380,7 @@ get_block_pk <- function(ctl0 = NULL, mrg_code = NULL, cmts = NULL){
351380
ind <- min(c(unlist(ind1),unlist(ind2),unlist(ind3),unlist(ind4),unlist(ind5),nchar(tmps[2])))
352381

353382
if(ind == nchar(tmps[2])){
354-
tmps[2] <- paste0(tmps[2],")")
383+
tmps[2] <- paste0(trimws(tmps[2]),")") # 06aug2024 added trimws
355384
}else{
356385
tmps[2] <- paste0(substr(tmps[2],1,ind-1),")",substr(tmps[2],ind,nchar(tmps[2])))
357386
}
@@ -542,7 +571,7 @@ get_block_table<- function(ctl0 = ctl, mrg_code = mrg_code, params = all_params,
542571
dplyr::filter(BLOCK == "TABLE")%>%
543572
dplyr::select(V1)%>%
544573
dplyr::mutate(V1 = paste(V1, collapse = " "))%>% # join all rows of input to single row
545-
dplyr::distinct() # remove duplicates
574+
dplyr::distinct() # remove duplicates; this line likely isn't needed/redundant, but leaving until time to test
546575

547576
input <- data.frame(V1 = strsplit(input$V1, "\\s")[[1]]) %>% # single row to many by white space
548577
dplyr::mutate(V1 = trimws(V1, which = "both"))%>% # remove white space
@@ -551,7 +580,8 @@ get_block_table<- function(ctl0 = ctl, mrg_code = mrg_code, params = all_params,
551580
input <- input %>%
552581
dplyr::filter(V1 != "$STABLE")%>%
553582
dplyr::filter(V1 %in% params)%>%
554-
dplyr::filter(!(V1 %in% cmts))
583+
dplyr::filter(!(V1 %in% cmts))%>%
584+
dplyr::distinct() # remove duplicates; 06aug2024
555585

556586
mrg_code <- mrg_code %>%
557587
dplyr::bind_rows(input)%>%

0 commit comments

Comments
 (0)