From peter.meilstrup at gmail.com  Fri Jan  3 03:15:53 2014
From: peter.meilstrup at gmail.com (Peter Meilstrup)
Date: Thu, 2 Jan 2014 18:15:53 -0800
Subject: [Rd] class() on substitute(...) output?
In-Reply-To: <CAFDcVCS7vdmRdnqYQvb3xq5C5x7+366b_SPisQeb9oX7vWHKRw@mail.gmail.com>
References: <CAFDcVCS7vdmRdnqYQvb3xq5C5x7+366b_SPisQeb9oX7vWHKRw@mail.gmail.com>
Message-ID: <CAJoaRhaqkKBr6OyOLLJJ9c+UJzr2Eq+MfoBHWj1_EUW4RMYYtA@mail.gmail.com>

I've found 'while', 'for', 'if' and '=' appearing as the "class" of
what would ostensibly be "call" objects, as well. (Came across this
because I was using S3 dispatch to help do code-walking syntax
transformations)

I can't find where it is happening in R source, but it seems
significant that they all are are things that deparse as other than
function calls, and all are symbols that have SET_SPECIAL_SYMBOL
marked in names.c --- although the converse does not hold for either
statement.


On Thu, Jan 2, 2014 at 5: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?
>
> Thanks,
>
> Henrik
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] class() on substitute(...) output?
Peter Meilstrup