diff --git a/R/clean_parameters.R b/R/clean_parameters.R index e4be16614..3a45d91f7 100644 --- a/R/clean_parameters.R +++ b/R/clean_parameters.R @@ -497,22 +497,22 @@ clean_parameters.mlm <- function(x, ...) { resp_pattern <- sprintf("_%s_(.*)", resp) for (i in resp_pattern) { - out$Cleaned_Parameter <- gsub(pattern = i, "_\\1", out$Cleaned_Parameter, perl = TRUE) + out$Cleaned_Parameter <- gsub(pattern = i, "_\\1", out$Cleaned_Parameter) } resp_pattern <- sprintf("__%s(.*)", resp) for (i in resp_pattern) { - out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) + out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter) } resp_pattern <- sprintf("__zi_%s(.*)", resp) for (i in resp_pattern) { - out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) + out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter) } resp_pattern <- sprintf("(sigma)(_%s)", resp) for (i in resp_pattern) { - out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter, perl = TRUE) + out$Cleaned_Parameter <- gsub(pattern = i, "\\1", out$Cleaned_Parameter) } } @@ -526,16 +526,16 @@ clean_parameters.mlm <- function(x, ...) { # clean fixed effects, conditional and zero-inflated out$Cleaned_Parameter <- gsub(pattern = "^b_(?!zi_)(.*)\\.(\\d)\\.$", "\\1[\\2]", out$Cleaned_Parameter, perl = TRUE) - out$Cleaned_Parameter <- gsub(pattern = "^b_zi_(.*)\\.(\\d)\\.$", "\\1[\\2]", out$Cleaned_Parameter, perl = TRUE) + out$Cleaned_Parameter <- gsub(pattern = "^b_zi_(.*)\\.(\\d)\\.$", "\\1[\\2]", out$Cleaned_Parameter) out$Cleaned_Parameter <- gsub(pattern = "^(b_|bs_|bsp_|bcs_)(?!zi_)(.*)", "\\2", out$Cleaned_Parameter, perl = TRUE) - out$Cleaned_Parameter <- gsub(pattern = "^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)(.*)", "\\2", out$Cleaned_Parameter, perl = TRUE) # nolint + out$Cleaned_Parameter <- gsub(pattern = "^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)(.*)", "\\2", out$Cleaned_Parameter) # nolint # correlation and sd cor_sd <- grepl("(sd_|cor_)(.*)", out$Cleaned_Parameter) if (any(cor_sd)) { - out$Cleaned_Parameter[cor_sd] <- gsub("^(sd_|cor_)(.*?)__(.*)", "\\3", out$Parameter[cor_sd], perl = TRUE) - out$Group[cor_sd] <- paste("SD/Cor:", gsub("^(sd_|cor_)(.*?)__(.*)", "\\2", out$Parameter[cor_sd], perl = TRUE)) + out$Cleaned_Parameter[cor_sd] <- gsub("^(sd_|cor_)(.*?)__(.*)", "\\3", out$Parameter[cor_sd]) + out$Group[cor_sd] <- paste("SD/Cor:", gsub("^(sd_|cor_)(.*?)__(.*)", "\\2", out$Parameter[cor_sd])) # replace "__" by "~" cor_only <- startsWith(out$Parameter[cor_sd], "cor_") if (any(cor_only)) { @@ -645,14 +645,14 @@ clean_parameters.mlm <- function(x, ...) { cor_sd <- startsWith(out$Cleaned_Parameter, "Sigma[") if (any(cor_sd)) { - parm1 <- gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\2", out$Parameter[cor_sd], perl = TRUE) - parm2 <- gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\3", out$Parameter[cor_sd], perl = TRUE) + parm1 <- gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\2", out$Parameter[cor_sd]) + parm2 <- gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\3", out$Parameter[cor_sd]) out$Cleaned_Parameter[which(cor_sd)] <- parm1 rand_cor <- parm1 != parm2 if (any(rand_cor)) { out$Cleaned_Parameter[which(cor_sd)[rand_cor]] <- paste0(parm1[rand_cor], " ~ ", parm2[rand_cor]) } - out$Group[cor_sd] <- paste("Var/Cov:", gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\1", out$Parameter[cor_sd], perl = TRUE)) + out$Group[cor_sd] <- paste("Var/Cov:", gsub("^Sigma\\[(.*):(.*),(.*)\\]", "\\1", out$Parameter[cor_sd])) } diff --git a/R/find_parameters_bayesian.R b/R/find_parameters_bayesian.R index 393a623ce..4c1573412 100644 --- a/R/find_parameters_bayesian.R +++ b/R/find_parameters_bayesian.R @@ -225,7 +225,7 @@ find_parameters.brmsfit <- function(x, # remove redundant columns. These seem to be new since brms 2.16? pattern <- "^[A-z]_\\d\\.\\d\\.(.*)" - fe <- fe[!grepl(pattern, fe, perl = TRUE)] + fe <- fe[!grepl(pattern, fe)] is_mv <- NULL @@ -233,21 +233,21 @@ find_parameters.brmsfit <- function(x, fe <- fe[!startsWith(fe, "Intercept")] cond <- fe[grepl("^(b_|bs_|bsp_|bcs_)(?!zi_)(.*)", fe, perl = TRUE)] - zi <- fe[grepl("^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)", fe, perl = TRUE)] + zi <- fe[grepl("^(b_zi_|bs_zi_|bsp_zi_|bcs_zi_)", fe)] rand <- fe[grepl("(?!.*__(zi|sigma|beta))(?=.*^r_)", fe, perl = TRUE) & !startsWith(fe, "prior_")] - randzi <- fe[grepl("^r_(.*__zi)", fe, perl = TRUE)] + randzi <- fe[grepl("^r_(.*__zi)", fe)] rand_sd <- fe[grepl("(?!.*_zi)(?=.*^sd_)", fe, perl = TRUE)] - randzi_sd <- fe[grepl("^sd_(.*_zi)", fe, perl = TRUE)] + randzi_sd <- fe[grepl("^sd_(.*_zi)", fe)] rand_cor <- fe[grepl("(?!.*_zi)(?=.*^cor_)", fe, perl = TRUE)] - randzi_cor <- fe[grepl("^cor_(.*_zi)", fe, perl = TRUE)] + randzi_cor <- fe[grepl("^cor_(.*_zi)", fe)] simo <- fe[startsWith(fe, "simo_")] car_struc <- fe[fe %in% c("car", "sdcar")] smooth_terms <- fe[startsWith(fe, "sds_")] priors <- fe[startsWith(fe, "prior_")] sigma_param <- fe[startsWith(fe, "sigma_") | grepl("sigma", fe, fixed = TRUE)] - randsigma <- fe[grepl("^r_(.*__sigma)", fe, perl = TRUE)] + randsigma <- fe[grepl("^r_(.*__sigma)", fe)] fixed_beta <- fe[grepl("beta", fe, fixed = TRUE)] - rand_beta <- fe[grepl("^r_(.*__beta)", fe, perl = TRUE)] + rand_beta <- fe[grepl("^r_(.*__beta)", fe)] mix <- fe[grepl("mix", fe, fixed = TRUE)] shiftprop <- fe[grepl("shiftprop", fe, fixed = TRUE)] dispersion <- fe[grepl("dispersion", fe, fixed = TRUE)] diff --git a/R/helper_functions.R b/R/helper_functions.R index 5a5f5b5ff..4ef896ca1 100644 --- a/R/helper_functions.R +++ b/R/helper_functions.R @@ -364,28 +364,13 @@ .grep_zi_smoothers <- function(x) { - grepl("^(s\\.\\d\\()", x, perl = TRUE) | - grepl("^(gam::s\\.\\d\\()", x, perl = TRUE) | - grepl("^(mgcv::s\\.\\d\\()", x, perl = TRUE) + # this one captures smoothers in zi- or mv-models from gam + grepl("^(s\\.\\d\\()", x) | grepl("^(gam::s\\.\\d\\()", x) | grepl("^(mgcv::s\\.\\d\\()", x) } .grep_non_smoothers <- function(x) { - !startsWith(x, "s(") & - # this one captures smoothers in zi- or mv-models from gam - grepl("^(?!(s\\.\\d\\())", x, perl = TRUE) & - !startsWith(x, "ti(") & - !startsWith(x, "te(") & - !startsWith(x, "t2(") & - !startsWith(x, "gam::s(") & - !startsWith(x, "VGAM::s(") & - !startsWith(x, "mgcv::s(") & - !startsWith(x, "mgcv::ti(") & - !startsWith(x, "mgcv::t2(") & - !startsWith(x, "mgcv::te(") & - !startsWith(x, "brms::s(") & - !startsWith(x, "brms::t2") & - !startsWith(x, "smooth_sd[") + !.grep_smoothers(x) & !.grep_zi_smoothers(x) } diff --git a/R/utilities.R b/R/utilities.R index 96b0dea3c..18c5fbd80 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -46,7 +46,7 @@ trim_ws <- function(x, ...) { #' @export trim_ws.default <- function(x, ...) { - gsub("^\\s+|\\s+$", "", x, perl = TRUE, useBytes = TRUE) + gsub("^\\s+|\\s+$", "", x, useBytes = TRUE) } #' @rdname trim_ws