I have strings, which describe mathematical formulas and I would like to convert it into lists of meaningful parts. The function ast_
does know how to parse it, to displays it as an Abstract Syntax Tree but does not return the AST. I am looking for a function which does return the tree.
bb <- "(media.urin_A + media.urin_B)/2"
lazyeval::ast_(rlang::parse_expr(bb))
> lazyeval::ast_(rlang::parse_expr(bb))
┗ ()
┗ `/
┗ ()
┗ `(
┗ ()
┗ `+
┗ `media.urin_A
┗ `media.urin_B
┗ 2
ast()
function is just for printing. You can just runas.list()
on the expression to turn it into a list which is basically the ast:as.list(rlang::parse_expr(bb))
. What exactly do you want to do with the result that you can't do in it's current form? You can use[]
and[[]]
indexing into an expression. – Stoll