From 498536ca56785c61451b1e38a0fc2131560d4d00 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Fri, 3 Mar 2023 11:06:52 +0800 Subject: [PATCH] Use writeLines, flexible regex for spaces --- R/rstan_config.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/rstan_config.R b/R/rstan_config.R index 4721b0f..66b4925 100644 --- a/R/rstan_config.R +++ b/R/rstan_config.R @@ -179,8 +179,8 @@ rstan_config <- function(pkgdir = ".") { if (grepl("\\.stanfunctions$", file_name) && (utils::packageVersion('rstan') < 2.29)) { mod <- readLines(file_name) - if (!any(grepl("\\bfunctions \\{", mod))) { - cat("functions {", mod, "}", sep = "\n", file = file_name) + if (!any(grepl("\\bfunctions(\\s*|)\\{", mod))) { + writeLines("functions {", mod, "}", sep = "\n", con = file_name) } } stanc_ret <- rstan::stanc(file_name, allow_undefined = TRUE,