Re: [R] How to take out the content of character string
Thank you all so much for the help! -- View this message in context: http://n4.nabble.com/How-to-take-out-the-content-of-character-string-tp1587004p1592886.html Sent from the R help mailing list archive at Nabble.com. __ 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] How to take out the content of character string
On Wed, 10 Mar 2010, Henrique Dallazuanna wrote: On Wed, Mar 10, 2010 at 7:50 PM, Thomas Lumley tlum...@u.washington.edu wrote: On Wed, 10 Mar 2010, baptiste auguie wrote: Hi, it's generally considered a bad practice but try this, eval(parse(text=AA)) library(fortunes) fortune(106) HTH, baptiste On 10 March 2010 07:46, jq81 jingqia...@gmail.com wrote: My question is represented by the following example. For example, I have a character string a, which is defined as AA=list(x=1, y=2) I want to take out the content of AA by using some function, so that I can obtain the following expression automatically. list(x=1, y=2) This is the situation where it isn't considered bad practice. If someone hands you a string with code in it, the only way to parse it is with parse(). I think that Is there another way: source(textConnection(AA))$value closeAllConnections() And if you look at the code for source(), you will see that it uses parse() and eval(). -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ 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] How to take out the content of character string
Hi, it's generally considered a bad practice but try this, eval(parse(text=AA)) library(fortunes) fortune(106) HTH, baptiste On 10 March 2010 07:46, jq81 jingqia...@gmail.com wrote: My question is represented by the following example. For example, I have a character string a, which is defined as AA=list(x=1, y=2) I want to take out the content of AA by using some function, so that I can obtain the following expression automatically. list(x=1, y=2) Does anyone know how to do it? Thanks a lot, -- View this message in context: http://n4.nabble.com/How-to-take-out-the-content-of-character-string-tp1587004p1587004.html Sent from the R help mailing list archive at Nabble.com. __ 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. -- Baptiste Auguié Departamento de Química Física, Universidade de Vigo, Campus Universitario, 36310, Vigo, Spain tel: +34 9868 18617 http://webs.uvigo.es/coloides __ 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] How to take out the content of character string
On Wed, 10 Mar 2010, baptiste auguie wrote: Hi, it's generally considered a bad practice but try this, eval(parse(text=AA)) library(fortunes) fortune(106) HTH, baptiste On 10 March 2010 07:46, jq81 jingqia...@gmail.com wrote: My question is represented by the following example. For example, I have a character string a, which is defined as AA=list(x=1, y=2) I want to take out the content of AA by using some function, so that I can obtain the following expression automatically. list(x=1, y=2) This is the situation where it isn't considered bad practice. If someone hands you a string with code in it, the only way to parse it is with parse(). The problem with eval(parse()) is when people use it to do macro processing or other things that are much better done with expressions. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ 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] How to take out the content of character string
On Wed, Mar 10, 2010 at 7:50 PM, Thomas Lumley tlum...@u.washington.edu wrote: On Wed, 10 Mar 2010, baptiste auguie wrote: Hi, it's generally considered a bad practice but try this, eval(parse(text=AA)) library(fortunes) fortune(106) HTH, baptiste On 10 March 2010 07:46, jq81 jingqia...@gmail.com wrote: My question is represented by the following example. For example, I have a character string a, which is defined as AA=list(x=1, y=2) I want to take out the content of AA by using some function, so that I can obtain the following expression automatically. list(x=1, y=2) This is the situation where it isn't considered bad practice. If someone hands you a string with code in it, the only way to parse it is with parse(). I think that Is there another way: source(textConnection(AA))$value closeAllConnections() The problem with eval(parse()) is when people use it to do macro processing or other things that are much better done with expressions. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.edu University of Washington, Seattle __ 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.
[R] How to take out the content of character string
My question is represented by the following example. For example, I have a character string a, which is defined as AA=list(x=1, y=2) I want to take out the content of AA by using some function, so that I can obtain the following expression automatically. list(x=1, y=2) Does anyone know how to do it? Thanks a lot, -- View this message in context: http://n4.nabble.com/How-to-take-out-the-content-of-character-string-tp1587004p1587004.html Sent from the R help mailing list archive at Nabble.com. __ 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.