Skip to content

Commit 5c4bcd7

Browse files
committed
fixes dangling 'else' that leads to code crash
1 parent 2396b63 commit 5c4bcd7

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

  • program/shinyApp/R/code_generation

program/shinyApp/R/code_generation/util.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ clean_function_code <- function(f) {
3434
# Trim any leading/trailing whitespace
3535
f_out <- trimws(f_out)
3636

37+
# Reattach `else`/`else if` to the preceding closing brace. deparse() places
38+
# `else` on its own line, which is valid inside a function body but a syntax
39+
# error once this body is inlined at the top level of the generated script.
40+
f_out <- gsub("\\}[[:space:]]*\\n[[:space:]]*else", "} else", f_out)
41+
3742
return(f_out)
3843
}
3944

0 commit comments

Comments
 (0)