Re: [R] History pruning

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Thu, 31 Jul 2008 15:12:03 -0400

On 7/31/2008 2:08 PM, Ken Williams wrote:

> 
> 
> On 7/31/08 11:01 AM, "hadley wickham" <h.wickham_at_gmail.com> wrote:
> 
>> I think that would be a very hard task -
> 
> Well, at least medium-hard.  But I think significant automatic steps could
> be made, and then a human can take over for the last few steps.  That's why
> I was enquiring about "tools" rather than a complete solution.
> 
> Does R provide facilities for introspection or interrogation of expression
> objects?  I couldn't find anything useful on first look:

You can index an expression as a list:

> e <- expression(foo <- 5 * bar)
>
> e[[1]]

foo <- 5 * bar
> str(e[[1]])

  language foo <- 5 * bar

expression() returns a list of language objects, and we only asked for one. We can look inside it:

> e[[1]][[1]]
`<-`

The as.list function is also useful:

> as.list(e[[1]])

[[1]]
`<-`

[[2]]
foo

[[3]]
5 * bar

and proceed recursively:

> as.list(e[[1]][[3]])

[[1]]
`*`

[[2]]
[1] 5

[[3]]
bar

Duncan Murdoch

>
>> methods(class="expression")
> no methods were found
>> dput(expression(foo <- 5 * bar))
> expression(foo <- 5 * bar)
>> str(expression(foo <- 5 * bar))
> expression(foo <- 5 * bar)
>
>
>> it's equivalent to taking a
>> long rambling conversation and then automatically turning it into a
>> concise summary of what was said. I think you must have human
>> intervention.
>
> It's not really equivalent, natural language has ambiguities and
subtleties
> that computer languages, especially functional languages, intentionally
> don't have. By their nature, computer languages can be turned into parse
> trees unambiguously and then those trees can be manipulated.
>
> But coincidentally I work in a Natural Language Processing group, and
one of
> the things we do is create exactly the kind of concise summaries you
> describe. =)
>



R-help_at_r-project.org 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. Received on Thu 31 Jul 2008 - 19:21:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 31 Jul 2008 - 21:33:14 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive