@@ -517,21 +517,21 @@ find_formula.afex_aov <- function(x, verbose = TRUE, ...) {
517
517
dv <- attr(x , " dv" )
518
518
id <- attr(x , " id" )
519
519
520
- within <- names(attr(x , " within" ))
521
- within <- paste0(within , collapse = " *" )
522
- within <- paste0(" (" , within , " )" )
523
- e <- paste0(" Error(" , id , " /" , within , " )" )
520
+ within_variables <- names(attr(x , " within" ))
521
+ within_variables <- paste0(within_variables , collapse = " *" )
522
+ within_variables <- paste0(" (" , within_variables , " )" )
523
+ e <- paste0(" Error(" , id , " /" , within_variables , " )" )
524
524
525
525
between <- names(attr(x , " between" ))
526
526
if (length(between ) > 0L ) {
527
527
tempf <- find_formula(x $ lm )[[1 ]]
528
528
between <- as.character(tempf )[3 ]
529
529
between <- paste0(" (" , between , " )" )
530
530
531
- within <- paste0(c(within , between ), collapse = " *" )
531
+ within_variables <- paste0(c(within_variables , between ), collapse = " *" )
532
532
}
533
533
534
- out <- list (conditional = stats :: formula(paste0(dv , " ~" , within , " +" , e )))
534
+ out <- list (conditional = stats :: formula(paste0(dv , " ~" , within_variables , " +" , e )))
535
535
class(out ) <- c(" insight_formula" , " list" )
536
536
out
537
537
}
@@ -600,12 +600,10 @@ find_formula.gls <- function(x, verbose = TRUE, ...) {
600
600
}
601
601
602
602
l <- tryCatch(
603
- {
604
- list (
605
- conditional = stats :: formula(x ),
606
- correlation = stats :: as.formula(f_corr )
607
- )
608
- },
603
+ list (
604
+ conditional = stats :: formula(x ),
605
+ correlation = stats :: as.formula(f_corr )
606
+ ),
609
607
error = function (x ) {
610
608
NULL
611
609
}
@@ -1267,6 +1265,16 @@ find_formula.sem <- function(x, verbose = TRUE, ...) {
1267
1265
# ' @export
1268
1266
find_formula.lme <- function (x , verbose = TRUE , ... ) {
1269
1267
fm <- stats :: formula(x $ terms )
1268
+ .find_formula_nlme(x , fm , verbose = verbose , ... )
1269
+ }
1270
+
1271
+ # ' @export
1272
+ find_formula.glmmPQL <- function (x , verbose = TRUE , ... ) {
1273
+ fm <- stats :: formula(x )
1274
+ .find_formula_nlme(x , fm , verbose = verbose , ... )
1275
+ }
1276
+
1277
+ .find_formula_nlme <- function (x , fm , verbose = TRUE , ... ) {
1270
1278
fmr <- eval(x $ call $ random )
1271
1279
if (! is.null(fmr ) && safe_deparse(fmr )[1 ] == " ~1" ) {
1272
1280
check_if_installed(" nlme" )
@@ -1364,12 +1372,10 @@ find_formula.BBmm <- function(x, verbose = TRUE, ...) {
1364
1372
# ' @export
1365
1373
find_formula.mmclogit <- function (x , verbose = TRUE , ... ) {
1366
1374
f <- tryCatch(
1367
- {
1368
- list (
1369
- conditional = stats :: formula(x ),
1370
- random = stats :: as.formula(parse(text = safe_deparse(x $ call ))[[1 ]]$ random )
1371
- )
1372
- },
1375
+ list (
1376
+ conditional = stats :: formula(x ),
1377
+ random = stats :: as.formula(parse(text = safe_deparse(x $ call ))[[1 ]]$ random )
1378
+ ),
1373
1379
error = function (x ) {
1374
1380
NULL
1375
1381
}
@@ -1418,12 +1424,10 @@ find_formula.stanreg <- function(x, verbose = TRUE, ...) {
1418
1424
# special handling for stan_gamm4
1419
1425
if (inherits(x , " gamm4" )) {
1420
1426
f.random <- tryCatch(
1421
- {
1422
- lapply(.findbars(stats :: formula(x $ glmod )), function (.x ) {
1423
- f <- safe_deparse(.x )
1424
- stats :: as.formula(paste0(" ~" , f ))
1425
- })
1426
- },
1427
+ lapply(.findbars(stats :: formula(x $ glmod )), function (.x ) {
1428
+ f <- safe_deparse(.x )
1429
+ stats :: as.formula(paste0(" ~" , f ))
1430
+ }),
1427
1431
error = function (e ) {
1428
1432
NULL
1429
1433
}
@@ -1484,8 +1488,8 @@ find_formula.MCMCglmm <- function(x, verbose = TRUE, ...) {
1484
1488
find_formula.BFBayesFactor <- function (x , verbose = TRUE , ... ) {
1485
1489
if (.classify_BFBayesFactor(x ) == " linear" ) {
1486
1490
fcond <- utils :: tail(x @ numerator , 1 )[[1 ]]@ identifier $ formula
1487
- dt <- utils :: tail(x @ numerator , 1 )[[1 ]]@ dataTypes
1488
- frand <- names(dt )[which(dt == " random" )]
1491
+ dat_types <- utils :: tail(x @ numerator , 1 )[[1 ]]@ dataTypes
1492
+ frand <- names(dat_types )[which(dat_types == " random" )]
1489
1493
1490
1494
if (is_empty_object(frand )) {
1491
1495
f.random <- NULL
@@ -1816,15 +1820,14 @@ find_formula.model_fit <- function(x, verbose = TRUE, ...) {
1816
1820
fc <- try(.formula_clean(f [[1 ]]), silent = TRUE )
1817
1821
if (inherits(fc , " try-error" )) {
1818
1822
format_error(attributes(fc )$ condition $ message )
1819
- } else {
1820
- if (verbose ) {
1821
- format_warning(paste0(
1822
- " Using `$` in model formulas can produce unexpected results. Specify your model using the `data` argument instead." , # nolint
1823
- " \n Try: " , fc $ formula , " , data = " , fc $ data
1824
- ))
1825
- }
1826
- return (FALSE )
1827
1823
}
1824
+ if (verbose ) {
1825
+ format_warning(paste0(
1826
+ " Using `$` in model formulas can produce unexpected results. Specify your model using the `data` argument instead." , # nolint
1827
+ " \n Try: " , fc $ formula , " , data = " , fc $ data
1828
+ ))
1829
+ }
1830
+ return (FALSE )
1828
1831
}
1829
1832
return (TRUE )
1830
1833
}
0 commit comments