[R] RE: [Rd] converting body of a function to a a character vector

Bill.Venables@CMIS.CSIRO.AU Bill.Venables at CMIS.CSIRO.AU
Tue Apr 17 14:07:31 CEST 2001


1. This query belongs in r-help, not in r-devel

2. Pity about your shift key...

3. The function you need is deparse() rather than as.character():

> fff <- function(x) {
+ x*x
+ }
> deparse(body(fff))
[1] "{" "x * x" "}"        
> 

4. There is a reason why as.character works this way.  It transforms to
character from a more fundamental representation of the language object, but
that's a larger story...

Bill Venables.

| -----Original Message-----
| From: Erich Neuwirth [mailto:erich.neuwirth at univie.ac.at]
| Sent: Tuesday, 17 April 2001 20:25
| Cc: r-devel at stat.math.ethz.ch
| Subject: [Rd] converting body of a function to a a character vector
| 
| 
| have a look at the following session:
| 
| > fff<-function(x)
| + {
| + x*x
| + }
| > fff
| function(x)
| {
| x*x
| }
| >
| > body(fff)
| {
|     x * x
| }
| > as.character(body(fff))
| [1] "{"     "x * x"
| 
| somehow,
| the closing parenthesis gets lost in the conversion.
| 
| i need this stuff because i want to get
| the code of a function as a vector of strings so i can get it
| into excel with my interface package.
| 
| 
| 
| --
| Erich Neuwirth, Computer Supported Didactics Working Group
| Visit our SunSITE at http://sunsite.univie.ac.at
| Phone: +43-1-4277-38624 Fax: +43-1-4277-9386
| -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.
| -.-.-.-.-.-.-.-.-
| r-devel mailing list -- Read 
http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._.
_._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list