Index: src/library/stats/R/princomp.R
===================================================================
--- src/library/stats/R/princomp.R	(revision 37571)
+++ src/library/stats/R/princomp.R	(working copy)
@@ -10,13 +10,14 @@
     mf$... <- NULL
     mf[[1]] <- as.name("model.frame")
     mf <- eval.parent(mf)
+    na.act <- attr(mf, "na.action")
+    mt <- attr(mf, "terms") # allow model.frame to update it
+    attr(mt, "intercept") <- 0
+    mterms <- attr(mt, "term.labels")
     ## this is not a `standard' model-fitting function,
     ## so no need to consider contrasts or levels
-    if(any(sapply(mf, function(x) is.factor(x) || !is.numeric(x))))
+    if(any(sapply(mterms, function(x) is.factor(mf[,x]) || !is.numeric(mf[,x]))))
         stop("PCA applies only to numerical variables")
-    na.act <- attr(mf, "na.action")
-    mt <- attr(mf, "terms") # allow model.frame to update it
-    attr(mt, "intercept") <- 0
     x <- model.matrix(mt, mf)
     res <- princomp.default(x, ...)
     ## fix up call to refer to the generic, but leave arg name as `formula'
Index: src/library/stats/R/prcomp.R
===================================================================
--- src/library/stats/R/prcomp.R	(revision 37571)
+++ src/library/stats/R/prcomp.R	(working copy)
@@ -37,13 +37,14 @@
     mf$... <- NULL
     mf[[1]] <- as.name("model.frame")
     mf <- eval.parent(mf)
+    na.act <- attr(mf, "na.action")
+    mt <- attr(mf, "terms")
+    attr(mt, "intercept") <- 0
+    mterms <- attr(mt, "term.labels")
     ## this is not a `standard' model-fitting function,
     ## so no need to consider contrasts or levels
-    if (any(sapply(mf, function(x) is.factor(x) || !is.numeric(x))))
+    if(any(sapply(mterms, function(x) is.factor(mf[,x]) || !is.numeric(mf[,x]))))
         stop("PCA applies only to numerical variables")
-    na.act <- attr(mf, "na.action")
-    mt <- attr(mf, "terms")
-    attr(mt, "intercept") <- 0
     x <- model.matrix(mt, mf)
     res <- prcomp.default(x, ...)
     ## fix up call to refer to the generic, but leave arg name as `formula'
