Re: [R] computing on expressions

2009-01-02 Thread Vadim Ogranovich
The following seems to work too:

expr2 - expression(a0)
expr2 - as.expression( bquote(.(expr2[[1]])  b0 ) )

Here as.expression converts the 'call' type returned by bquote to 'expression' 
type.

Thanks again Dunkan.

Vadim

-Original Message-
From: Duncan Murdoch [mailto:murd...@stats.uwo.ca]
Sent: Friday, October 03, 2008 11:41 AM
To: Vadim Organovich
Cc: r-help@r-project.org
Subject: Re: [R] computing on expressions

On 10/3/2008 11:48 AM, Vadim Organovich wrote:
 Dear R-users,

 Suppose I have an expression:

 expr = expression(a0)

 and now I want to modify it to expression(a0  b0). The following doesn't 
 work:

 expr = expression(expr  b0)

 What would be a good way of doing this?

I'd avoid using parse because it doesn't generalize well.  Here's a way
to do it without that.  But first, some background:

expression() returns a special kind of list that contains language
objects.  So expr[[1]] is initially  a0, and you want to change it to
a0  b0.  I think you don't really want expr  b0, because that would
beexpression(a0)  b0  which is nonsense.

The bquote() function is probably the easiest way to make substitutions.
  The idea is that you write out the answer you want within bquote(),
using .() around things you want substituted.  (You can also use the
substitute() function, but it's a little trickier.)

Putting these together, this gives you the final result you want:

expr - expression(a0)
expr[[1]] - bquote( .(expr[[1]])  b0 )

The following lines almost give you what you want:

expr2 - expression(a0)
expr2 - bquote( expression( .(expr2[[1]])  b0 ) )

but not quite:  expr2 becomes an unevaluated call to the expression()
function, not an actual expression (though they print the same).  You
need this for the equivalent to the first version:

expr2 - expression(a0)
expr2 - eval( bquote( expression( .(expr2[[1]])  b0 ) ) )

Duncan Murdoch

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.


Re: [R] computing on expressions

2008-10-03 Thread Henrique Dallazuanna
Try this:

parse(text = paste(capture.output(expr[[1]]),   b  0))

On Fri, Oct 3, 2008 at 12:48 PM, Vadim Organovich
[EMAIL PROTECTED] wrote:
 Dear R-users,

 Suppose I have an expression:

 expr = expression(a0)

 and now I want to modify it to expression(a0  b0). The following doesn't 
 work:

 expr = expression(expr  b0)

 What would be a good way of doing this?

 Thanks,
 Vadim

 
 Note: This email is for the confidential use of the named addressee(s) only 
 and may contain proprietary, confidential or privileged information. If you 
 are not the intended recipient, you are hereby notified that any review, 
 dissemination or copying of this email is strictly prohibited, and to please 
 notify the sender immediately and destroy this email and any attachments. 
 Email transmission cannot be guaranteed to be secure or error-free. Jump 
 Trading, therefore, does not make any guarantees as to the completeness or 
 accuracy of this email or any attachments. This email is for informational 
 purposes only and does not constitute a recommendation, offer, request or 
 solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
 of transaction of a financial product.

[[alternative HTML version deleted]]

 __
 R-help@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.




-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

__
R-help@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.


Re: [R] computing on expressions

2008-10-03 Thread Vadim Organovich
Thanks!

Here is a less verbose variation based on suggestion by Phil Spector:

parse(text=paste(expression(a0),  b0))


From: Henrique Dallazuanna [EMAIL PROTECTED]
Sent: Friday, October 03, 2008 11:08 AM
To: Vadim Organovich
Cc: r-help@r-project.org
Subject: Re: [R] computing on expressions

Try this:

parse(text = paste(capture.output(expr[[1]]),   b  0))

On Fri, Oct 3, 2008 at 12:48 PM, Vadim Organovich
[EMAIL PROTECTED] wrote:
 Dear R-users,

 Suppose I have an expression:

 expr = expression(a0)

 and now I want to modify it to expression(a0  b0). The following doesn't 
 work:

 expr = expression(expr  b0)

 What would be a good way of doing this?

 Thanks,
 Vadim

 
 Note: This email is for the confidential use of the named addressee(s) only 
 and may contain proprietary, confidential or privileged information. If you 
 are not the intended recipient, you are hereby notified that any review, 
 dissemination or copying of this email is strictly prohibited, and to please 
 notify the sender immediately and destroy this email and any attachments. 
 Email transmission cannot be guaranteed to be secure or error-free. Jump 
 Trading, therefore, does not make any guarantees as to the completeness or 
 accuracy of this email or any attachments. This email is for informational 
 purposes only and does not constitute a recommendation, offer, request or 
 solicitation of any kind to buy, sell, subscribe, redeem or perform any type 
 of transaction of a financial product.

[[alternative HTML version deleted]]

 __
 R-help@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.




--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40 S 49° 16' 22 O

Note: This email is for the confidential use of the named addressee(s) only and 
may contain proprietary, confidential or privileged information. If you are not 
the intended recipient, you are hereby notified that any review, dissemination 
or copying of this email is strictly prohibited, and to please notify the 
sender immediately and destroy this email and any attachments.  Email 
transmission cannot be guaranteed to be secure or error-free.  Jump Trading, 
therefore, does not make any guarantees as to the completeness or accuracy of 
this email or any attachments.  This email is for informational purposes only 
and does not constitute a recommendation, offer, request or solicitation of any 
kind to buy, sell, subscribe, redeem or perform any type of transaction of a 
financial product.

__
R-help@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.