(Ted Harding) wrote:
On 09-Aug-09 16:53:32, Douglas Bates wrote:
On Sun, Aug 9, 2009 at 11:32 AM, Ted
Harding<[email protected]> wrote:
On 09-Aug-09 16:06:52, Peng Yu wrote:
Hi,
I know '.' is not a separator in R as in C++. I am wondering where it
discusses the detailed usage of '.' in R. Can somebody point me a
webpage, a manual or a book that discuss this?
Regards,
Peng
To the best of my knowledge, apart from its specific use as a
separator
between the integer and fractional parts of a number, "." has no
specific
use in R, and you can, for instance, use it just as you would use an
alphanumeric character in a name.
For instance, you could do
_. <- 1.2345
_.
_# [1] 1.2345
_. <- function(x) x^2
_.(12)
_# [1] 144
So, unless there is something I don't know about, there is hardly
anything to discuss about "the detailed usage of '.' in R"!
The ',' character is one of the characters allowed in names, hence it
can be used as you have suggested. There are (at least) two special
usages of the '.' in names. Following the time-honoured Unix
convention, names that begin with '.' are considered "hidden" names
and not listed by ls() or objects() unless you set all.names = TRUE in
the call. Because of this convention it is inadvisable to use names
starting with '.' except when you wish to avoid potential name
conflicts. The second special use of '.' in a name is in the
construction of the names of S3 method functions. The method for
generic function "foo" applied to class "bar" is named "foo.bar".
As in "summary.glm", I suppose! However, this prompts a question.
In the first place, the construction of "summary.glm" from "summary"
and "glm" is, in the first instance, simply using "." in its basic
role as a permissible character in a name. Correct?
Correct.
Next -- and this is the real question -- how does R parse the name
"summary.glm"? In my naivety, I simply suppose that it looks for
an available function whose name is "summary.glm" in just the
same way as it looks for "stopifnot", or for that matter "data.matrix"
which is not (as far as I know) a compound of a generic function
"data" applied to a class "matrix". Then "." would not have a special
(parseable) role in the name -- it is simply another "letter".
It doesn't do anything special when parsing. The special sauce comes
when the generic summary() function executes UseMethod("summary"). At
that point, we know the class of the object, and we know the name of the
generic, so it goes looking for a summary.glm method.
There are some subtleties to how it does that lookup (see the discussion
in Writing R Extensions about NAMESPACES), but if you had a generic
function calling UseMethod("data") and it was passed an object of class
"matrix", data.matrix() would be called, even though that doesn't make
sense. This is a flaw in the S3 system, and one of the motivations for
the development of the S4 system.
Duncan Murdoch
But when you do have such a function, like "summary.glm", does R
in fact parse it as "summary" then "glm" (i.e. look out for the
generic function "summary" and then specialise it to handle "glm").
As I say, I suppose not. And, if not, then the "special use" of
the character "." is simply a programmer's convention for the
construction of the name, and once the name exists the "." does
not have a special (parseable) significance for R.
Just seeking clarification ... !
Thanks,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <[email protected]>
Fax-to-email: +44 (0)870 094 0861
Date: 09-Aug-09 Time: 19:58:32
------------------------------ XFMail ------------------------------
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.