[ESS] Equivalent to RStudio 'Extract Function'

Charles Berry ccberry at ucsd.edu
Mon Feb 17 18:14:34 CET 2014


Vitalie Spinu <spinuvit <at> gmail.com> writes:

[snip]

> 
> 
> Suggestions of things to "steal" from R-studio are welcome;). Earlier or
> later I will find time to implement them.
> 

Maybe look at what codetools:::findGlobals() does.

Here is an example:

,----
| > library(codetools)
| > expr.2.functionize <-
| +     expression({
| +         a <- b
| +         c <- a + d
| +     })
| > fun <- function() {}
| > body(fun) <- expr.2.functionize
| > vnames <- findGlobals(fun,merge=F)$variables
| > formals(fun) <-
| +     structure( rep(alist(z=),length(vnames)),
| +                names=vnames )
| > fun
| function (b, d) 
| {
|     a <- b
|     c <- a + d
| }
`----


HTH,

Chuck



More information about the ESS-help mailing list