[R] Transforming a string into a command

David Winsemius dwinsemius at comcast.net
Tue Nov 29 15:31:30 CET 2011


On Nov 29, 2011, at 2:30 AM, Xu Wang wrote:

> David,
>
> Did my reply get orphaned

All replies are "orphaned".  You are asked to include context if your  
question relies on code that has previously been posted.

> or are you trying to help me realize that asking
> why something does not work is not a straightforward question? I'll  
> try to
> cover both bases.
>
> I'll focus just on the first case that I don't understand. Suppose  
> we have
> s<- "ln(a+b)"
> a<-1
> b<-2
> eval(parse(text=s))
> Error in eval(expr, envir, enclos) : could not find function "ln"



>
> Perhaps it's because I don't understand eval well (any good  
> references for
> reading up on eval, parse, substitute, etc.?).

It appears you need to review the help page for the `log` function.

> But I expected it to produce
> the same as the following line:
> eval(parse(text="ln(a+b)"))

It did.

 > eval(parse(text="ln(a+b)"))
Error in eval(expr, envir, enclos) : could not find function "ln"

>
> Xu
>
>
> David Winsemius wrote
>>
>> On Nov 29, 2011, at 2:00 AM, Xu Wang wrote:
>>
>>> Why don't the following two commands work?
>>>
>>> eval(parse(text=s))
>>> eval(as.expression(s))
>>>

They both "worked" as expected. An error was appropriately reported.

 > ln(a+b)
Error: could not find function "ln"

 > log(a+b)
[1] 1.098612



>>
>> Can you think of anything else we might need to know in order to
>> answer that question?


Some Nabble users seem to expect that the rest of Rhelp sees what they  
see. They are delusional when they do so.

-- 
David.
> --
> View this message in context: http://r.789695.n4.nabble.com/Transforming-a-string-into-a-command-tp4112183p4118294.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list