I would like to make a string executable, e.g, s<- "ln(a+b)" a<-1 b<-2 ???? execute string s to obtain ln(a+b) ???? How can I make it? Ciao fron Rome Vittorio
Transforming a string into a command
11 messages · Victor, Michael Kao, andrija djurovic +4 more
This is one way to do it. a = 1 b = 2 c = parse(text = "log(a + b)") eval(c) Hope this helps. Cheers,
On 27/11/2011 11:16 a.m., Victor wrote:
I would like to make a string executable, e.g, s<- "ln(a+b)" a<-1 b<-2 ???? execute string s to obtain ln(a+b) ???? How can I make it? Ciao fron Rome Vittorio
______________________________________________ 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.
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111127/05205adb/attachment.pl>
1 day later
Why don't the following two commands work? eval(parse(text=s)) eval(as.expression(s)) -- View this message in context: http://r.789695.n4.nabble.com/Transforming-a-string-into-a-command-tp4112183p4118243.html Sent from the R help mailing list archive at Nabble.com.
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))
Can you think of anything else we might need to know in order to answer that question?
David Winsemius, MD West Hartford, CT
David, Did my reply get orphaned 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.?). But I expected it to produce the same as the following line: eval(parse(text="ln(a+b)")) 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))
Can you think of anything else we might need to know in order to answer that question? -- David Winsemius, MD West Hartford, CT
______________________________________________ R-help@ 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.
-- 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.
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))
Hm, try to set an object s before calling. Regards Petr
______________________________________________ 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.
Hi
Did my reply get orphaned 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"
What is function ln supposed to do and to what package it belongs. I get
?ln
No documentation for ?ln? in specified packages and libraries: you could try ???ln? but it does not mean that ln is not used elsewhere. Regards Petr
Perhaps it's because I don't understand eval well (any good references
for
reading up on eval, parse, substitute, etc.?). But I expected it to
produce
the same as the following line: eval(parse(text="ln(a+b)")) 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))
Can you think of anything else we might need to know in order to answer that question? -- David Winsemius, MD West Hartford, CT
______________________________________________ R-help@ 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.
-- 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.
______________________________________________ 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.
On 11/29/2011 06:30 PM, Xu Wang wrote:
David, Did my reply get orphaned 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.?). But I expected it to produce the same as the following line: eval(parse(text="ln(a+b)"))
Hi Xu, Try: s<-"log(a+b)" a<-1 b<-2 eval(parse(text=s)) [1] 1.098612 There is no "ln" function in the base package. Jim
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111129/d452eb19/attachment.pl>