diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/model.R b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/model.R index 2175ac8d653c38340f7b99f3a51baa4a5b5bf1b8..5827c72a338b2b632e8f63746c9389a23316fe74 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/model.R +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/model.R @@ -502,9 +502,10 @@ replaceDots <- function(x, replacement) { } return(x) } - - for (i in seq_along(x)) { - x[[i]] <- replaceDots(x[[i]], replacement); + if (is.language(x)) { + for (i in seq_along(x)) { + x[[i]] <- replaceDots(x[[i]], replacement); + } } x } @@ -682,7 +683,11 @@ termsform <- function (x.in, specials, data, keep.order, allowDotAsName) { # Step 6: Fix up the formula by substituting for dot, which should be # the framenames joined by + if (haveDot) { - x <- ExpandDots(x, framenames) + if (length(framenames) > 0) { + x <- ExpandDots(x, framenames) + } else if (!allowDotAsName) { + error("'.' in formula and no 'data' argument") + } } attr(x, "order") <- ord diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 36982bf2ae2cf959a9573a433cccb1a35f50c50c..1589d9a4709b19317a4c41ff9db479ca6ab967d2 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -161126,6 +161126,30 @@ attr(,"assign") 15 2 2 99.190 16 2 2 16.000 +##com.oracle.truffle.r.test.library.stats.TestFormulae.testDotWithData# +#terms.formula(x ~ .^4, data=data.frame(1:5)) +x ~ X1.5^4 +attr(,"variables") +list(x, X1.5) +attr(,"factors") + X1.5 +x 0 +X1.5 1 +attr(,"term.labels") +[1] "X1.5" +attr(,"order") +[1] 1 +attr(,"intercept") +[1] 1 +attr(,"response") +[1] 1 +attr(,".Environment") +<environment: R_GlobalEnv> + +##com.oracle.truffle.r.test.library.stats.TestFormulae.testDotWithNoFramenames#Output.IgnoreErrorContext# +#terms.formula(x ~ .^4) +Error in terms.formula(x ~ .^4) : '.' in formula and no 'data' argument + ##com.oracle.truffle.r.test.library.stats.TestFormulae.testExpandDostsAndSpecialsTermsform# #f <- terms.formula(cyl~myfun(mpg)+., specials=c('myfun'), data=mtcars); attrs <- attributes(f); envIdx <- which(names(attrs)=='.Environment'); print(attrs[envIdx]); attrs[sort(names(attrs[-envIdx]))] $.Environment diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestFormulae.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestFormulae.java index 76faa10ddb6f317796b42ff353e03a8aee98c84d..06692c4ac63f82f90e12a215374721b6742e7037 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestFormulae.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestFormulae.java @@ -105,4 +105,14 @@ public class TestFormulae extends TestBase { public void testExpandDostsAndSpecialsTermsform() { assertEval("f <- terms.formula(cyl~myfun(mpg)+., specials=c('myfun'), data=mtcars); attrs <- attributes(f); " + SHOW_ATTRS); } + + @Test + public void testDotWithData() { + assertEval("terms.formula(x ~ .^4, data=data.frame(1:5))"); + } + + @Test + public void testDotWithNoFramenames() { + assertEval(Output.IgnoreErrorContext, "terms.formula(x ~ .^4)"); + } }