From h.wickham at gmail.com  Fri Jan  3 18:46:48 2014
From: h.wickham at gmail.com (Hadley Wickham)
Date: Fri, 3 Jan 2014 11:46:48 -0600
Subject: [Rd] class() on substitute(...) output?
In-Reply-To: <CAFDcVCS7vdmRdnqYQvb3xq5C5x7+366b_SPisQeb9oX7vWHKRw@mail.gmail.com>
References: <CAFDcVCS7vdmRdnqYQvb3xq5C5x7+366b_SPisQeb9oX7vWHKRw@mail.gmail.com>
Message-ID: <CABdHhvF+kR19Gqd-gTrZNK0k8QfuY+3QykbqD=Qwg_yP_O9sOw@mail.gmail.com>

On Thu, Jan 2, 2014 at 7:16 PM, Henrik Bengtsson <hb at biostat.ucsf.edu> wrote:
> Does it make sense to talk about the class of the output of
> substitute(...)?  I'm puzzled by the following outputs:
>
> ee <- list(
>   A = substitute( a <- 1 ),
>   B = substitute({ a <- 1 }),
>   C = substitute(( a <- 1 )),
>   D = substitute( a == 1 )
> )
>
>> t(sapply(ee, FUN=function(e) { c(typeof=typeof(e), mode=mode(e), class=class(e)) }))
>   typeof     mode   class
> A "language" "call" "<-"
> B "language" "call" "{"
> C "language" "("    "("
> D "language" "call" "call"
>
> That the mode in C is "(", is motivated in help("mode"): "that some
> calls have mode "(" which is S compatible."  However, what's the
> explanation for the different classes?  Is that intended or just
> "garbage" output?

?class has:

"Many R objects have a class attribute, a character vector giving the
names of the classes from which the object inherits. If the object
does not have a class attribute, it has an implicit class, "matrix",
"array" or the result of mode(x) (except that integer vectors have
implicit class "integer"). (Functions oldClass and oldClass<- get and
set the attribute, which can also be done directly.)"

which suggests either a bug or some tweaks are needed to the documentation.

Is there any point in ever using mode() except for S+ compatibility?
It just adds some confusing aliases on top of typeof.

Hadley

-- 
http://had.co.nz/



[Rd] class() on substitute(...) output?
Hadley Wickham