[R] Extract function parameters from a R expression

Hadley Wickham h@w|ckh@m @end|ng |rom gm@||@com
Wed Jun 20 10:26:10 CEST 2018


You need to recursively walk the parse tree/AST. See, e.g.,
https://adv-r.hadley.nz/expressions.html#ast-funs

Hadley

On Wed, Jun 20, 2018 at 10:08 AM, Sigbert Klinke
<sigbert using wiwi.hu-berlin.de> wrote:
> Hi,
>
> I have read an R program with
>
> expr <- parse("myRprg.R")
>
> How can I extract the parameters of a specifc R command, e.g. "library"?
>
> So, if myprg.R containes the lines
>
> library("xyz")
> library("abc")
>
> then I would like to get "xyz" and "abc" back from expr.
>
> Thanks in advance
>
> Sigbert
>
> --
> https://hu.berlin/sk
>
>
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>



-- 
http://hadley.nz




More information about the R-help mailing list