Re: [Rd] Very Long Expressions

From: Roger D. Peng <rpeng_at_jhsph.edu>
Date: Mon 24 Jan 2005 - 23:54:10 EST

Try

options(expressions = 1000)
eval(parse(text = paste(rep(1, 499), collapse = "+")))

-roger

McGehee, Robert wrote:
> Greetings,
> I'm having some difficulties with evaluating very long expressions
> (Windows/Linux 2.0.1), as seen below, and would greatly appreciate any
> help, thoughts or work arounds. Let's say that I wanted to see what I
> would get if I added 1 to itself 498 times. One way of doing this would
> be to evaluate the expression 1+1+1+...
>
>

>>eval(parse(text = paste(rep(1, 498), collapse = "+")))

>
> [1] 498
>
> However, if we try this with 499+ items we get no answer:
>
>>a <- eval(parse(text = paste(rep(1, 499), collapse = "+")))
>>a

>
> Error: Object "a" not found
>
> And if this eval is passed to any other function, that function exits
> without error and without returning and object.
>
> So it seems that we've reached some upper limit of evaluation terms.
> While the parser is able to correctly create the long expression, eval
> does not successfully evaluate it.
>
> My problem is that since the evaluator does not return an objec
t, error,
> or warning, I'm not able to easily code around this problem. Also, I've
> thought of no easy way to "count" the terms in the expression to see
> whether we've breached the upper limit or not.
>
> If I were able to see if the eval would work on a particular expression,
> one thing I had considered was to make an eval.long wrapper that peels

> terms off the right hand side of an overly-long expression until every

> sub-expression is legal.
>
> Thus, to count to 600 I could just add the first 497 terms with the next
> 103 terms.
>
>>eval(parse(text = paste(rep(1, 497), collapse = "+"))) +

>
> eval(parse(text = paste(rep(1, 103), collapse = "+")))
> [1] 600
>
> But without an error or way of figuring out if the expression would even
> be evaluated, I'm not sure how to know when to start or stop the peeling
> process. It also may become more complicated when parentheses are
> introduced.
>
> Any help would be greatly appreciated.
>
> Thanks,
> Robert
>
> platform i386-pc-mingw32
> arch i386
> os mingw32
> system i386, mingw32
> status
> major 2
> minor 0.1
> year 2004
> month 11
> day 15
> language R
>
> Robert McGehee
> Geode Capital Management, LLC
> 53 State Street, 5th Floor | Boston, MA | 02109
> Tel: 617/392-8396 Fax:617/476-6389
> mailto:robert.mcgehee@geodecapital.com
>
>
>
> This e-mail, and any attachments hereto, are intended for use by the
> addressee(s) only and may contain information that is (i) confidential
> information of Geode Capital Management, LLC and/or its affiliates,
> and/or (ii) proprietary information of Geode Capital Management, LLC

> and/or its affiliates. If you are not the intended recipient of this
> e-mail, or if you have otherwise received this e-mail in error, please
> immediately notify me by telephone (you may call collect), or by e-mail,
> and please permanently delete the original, any print outs and any
> copies of the foregoing. Any dissemination, distribution or copying of
> this e-mail is strictly prohibited.
>
> ______________________________________________
> R-devel@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
-- 
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/

______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Mon Jan 24 23:49:50 2005

This archive was generated by hypermail 2.1.8 : Tue 25 Jan 2005 - 01:23:31 EST