@@ -172,8 +172,9 @@ add1.lm <- function(object, scope, scale = 0, test=c("none", "Chisq", "F"),
172172    class(z ) <-  " lm" #  needed as deviance.lm calls generic residuals()
173173    RSS [1L ] <-  deviance(z )
174174    # # workaround for PR#7842. terms.formula may have flipped interactions
175-     sTerms  <-  sapply(strsplit(Terms , " :" fixed = TRUE ),
176-                      function (x ) paste(sort(x ), collapse = " :" 
175+     sTerms  <-  vapply(strsplit(Terms , " :" fixed = TRUE ),
176+                      function (x ) paste(sort(x ), collapse = " :" 
177+                      " " 
177178    for (tt  in  scope ) {
178179        stt  <-  paste(sort(strsplit(tt , " :" 1L ]]), collapse = " :" 
179180	usex  <-  match(asgn , match(stt , sTerms ), 0L ) >  0L 
@@ -291,8 +292,9 @@ add1.glm <- function(object, scope, scale = 0,
291292    r  <-  z $ residuals 
292293    w  <-  z $ weights 
293294    # # workaround for PR#7842. terms.formula may have flipped interactions
294-     sTerms  <-  sapply(strsplit(Terms , " :" fixed = TRUE ),
295-                      function (x ) paste(sort(x ), collapse = " :" 
295+     sTerms  <-  vapply(strsplit(Terms , " :" fixed = TRUE ),
296+                      function (x ) paste(sort(x ), collapse = " :" 
297+                      " " 
296298    for (tt  in  scope ) {
297299        stt  <-  paste(sort(strsplit(tt , " :" 1L ]]), collapse = " :" 
298300	usex  <-  match(asgn , match(stt , sTerms ), 0L ) >  0L 
@@ -623,10 +625,12 @@ factor.scope <- function(factor, scope)
623625	    nmfac  <-  colnames(factor )
624626            # # workaround as in PR#7842.
625627            # # terms.formula may have flipped interactions
626-             nmfac0  <-  sapply(strsplit(nmfac , " :" fixed = TRUE ),
627-                              function (x ) paste(sort(x ), collapse = " :" 
628-             nmdrop0  <-  sapply(strsplit(nmdrop , " :" fixed = TRUE ),
629-                              function (x ) paste(sort(x ), collapse = " :" 
628+             nmfac0  <-  vapply(strsplit(nmfac , " :" fixed = TRUE ),
629+                              function (x ) paste(sort(x ), collapse = " :" 
630+                              " " 
631+             nmdrop0  <-  vapply(strsplit(nmdrop , " :" fixed = TRUE ),
632+                               function (x ) paste(sort(x ), collapse = " :" 
633+                               " " 
630634	    where  <-  match(nmdrop0 , nmfac0 , 0L )
631635	    if (any(! where ))
632636                stop(sprintf(ngettext(sum(where == 0 ),
@@ -653,10 +657,12 @@ factor.scope <- function(factor, scope)
653657	if (! is.null(nmfac )) {
654658            # # workaround as in PR#7842.
655659            # # terms.formula may have flipped interactions
656-             nmfac0  <-  sapply(strsplit(nmfac , " :" fixed = TRUE ),
657-                              function (x ) paste(sort(x ), collapse = " :" 
658-             nmadd0  <-  sapply(strsplit(nmadd , " :" fixed = TRUE ),
659-                              function (x ) paste(sort(x ), collapse = " :" 
660+             nmfac0  <-  vapply(strsplit(nmfac , " :" fixed = TRUE ),
661+                              function (x ) paste(sort(x ), collapse = " :" 
662+                              " " 
663+             nmadd0  <-  vapply(strsplit(nmadd , " :" fixed = TRUE ),
664+                              function (x ) paste(sort(x ), collapse = " :" 
665+                              " " 
660666	    where  <-  match(nmfac0 , nmadd0 , 0L )
661667	    if (any(! where ))
662668                stop(sprintf(ngettext(sum(where == 0 ),
0 commit comments