Skip to content

Commit 8ffeffb

Browse files
author
maechler
committed
doc update for r88066, terms.formula( specials )
git-svn-id: https://svn.r-project.org/R/trunk@88161 00db46b3-68df-0310-9c12-caf00c1e9a41
1 parent f402a83 commit 8ffeffb

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

doc/NEWS.Rd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
\subsection{NEW FEATURES}{
1616
\itemize{
1717
\item \code{str()} now shows more via \code{format()} for external pointers.
18+
19+
\item \code{terms(<formula>, specials = *)} now treats non-syntactic
20+
specials more gracefully, thanks to \I{Mikael Jagan}'s \PR{18568}.
1821
}
1922
}
2023
@@ -302,9 +305,6 @@
302305
\item \code{selectMethod(f, ..)} now keeps the function name if the
303306
function belongs to a group generic and the method is for the
304307
generic.
305-
306-
\item \code{terms(<formula>, specials = *)} now treats non-syntactic
307-
specials more gracefully, thanks to \I{Mikael Jagan}'s \PR{18568}.
308308
}
309309
}
310310

src/library/stats/man/formula.Rd

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,17 @@ as.formula(object, env = parent.frame())
9494
formulae, although there is no guarantee that all code using formulae
9595
will accept such non-syntactic names.
9696

97-
Most model-fitting functions accept formulae with right-hand-side
98-
including the function \code{\link{offset}} to indicate terms with a
99-
fixed coefficient of one. Some functions accept other
100-
\sQuote{specials} such as \code{strata} or \code{cluster} (see the
101-
\code{specials} argument of \code{\link{terms.formula}}).
97+
Most model-fitting functions accept formulae with right-hand side
98+
containing calls to function \code{\link{offset}}. These calls
99+
indicate terms with coefficient fixed to one. Some model-fitting
100+
functions recognize other \dQuote{specials} like \code{strata} and
101+
\code{cluster} (typically by setting the \code{specials} argument of
102+
\code{\link{terms.formula}}). Because specials are nothing more than
103+
syntax, disambiguation using \code{\link{::}} or similar is nonsense
104+
(even if packages happen to define so-named functions) and the result
105+
is often a model that the user does not intend. For example, the
106+
formula \code{y ~ stats::offset(w) + x} does \emph{not} specify a
107+
model in which the coefficient of \code{w} is fixed to one.
102108

103109
There are two special interpretations of \code{.} in a formula. The
104110
usual one is in the context of a \code{data} argument of model

src/library/stats/man/terms.formula.Rd

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
}
1919
\arguments{
2020
\item{x}{a \code{\link{formula}}.}
21-
\item{specials}{which functions in the formula should be marked as
22-
special in the \code{terms} object? A character vector or \code{NULL}.}
21+
\item{specials}{an optional character vector listing names of
22+
functions. Calls to these functions in the formula are marked as
23+
special in the \code{terms} object.}
2324
\item{abb}{Not implemented in \R; deprecated.}
2425
\item{data}{a data frame from which the meaning of the special symbol
2526
\code{.} can be inferred. It is used only if there is a \code{.} in
@@ -37,6 +38,13 @@
3738
remaining variables contained in \code{data}. Exceptionally,
3839
\code{.} can be treated as a name for non-standard uses of formulae.}
3940
}
41+
\details{
42+
Non-syntactic \code{specials} are supported since \R{} 4.6.0.
43+
\code{specials="\var{pkg}::\var{name}"} marks as special calls
44+
\code{`\var{pkg}::\var{name}`(\dots)} (note backticks) and \emph{not}
45+
calls \code{\var{pkg}::\var{name}(\dots)}. The reverse was true prior
46+
to \R{} 4.6.0, but that was undocumented and accidental.
47+
}
4048
%% \note{
4149
%% Not all of the options work in the same way that they did in S and not
4250
%% all are implemented.

src/library/stats/man/terms.object.Rd

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ rownames(attr(tf, "factors"))[attr(tf, "specials")$s]
8282

8383
## we can keep the order by
8484
terms(y ~ x + x:z + s(x), specials = "s", keep.order = TRUE)
85+
86+
## use of '::' in terms to be marked as special is *wrong*
87+
ff <- list(y ~ offset(w) + x1 + s(x2),
88+
y ~ stats::offset(w) + x1 + mgcv::s(x2))
89+
tt <- lapply(ff, terms, specials = c("s", "mgcv::s"))
90+
lapply(tt, attr, "offset")
91+
lapply(tt, attr, "specials")
8592
}
8693
%%--- MM: I would really like instructive examples here...
8794
\keyword{models}

0 commit comments

Comments
 (0)