Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seeking to use call_tree to get a list object #53

Open
harryprince opened this issue Nov 17, 2016 · 0 comments
Open

seeking to use call_tree to get a list object #53

harryprince opened this issue Nov 17, 2016 · 0 comments

Comments

@harryprince
Copy link

harryprince commented Nov 17, 2016

I am seeking to catch pryr::call_tree output, definitely, I failed.
Because I find the call_tree function use cat function to throw output.

I am trying to use pryr::call_tree to analysis the abstract grammar tree to leverage the power of %>% in dplyr to plot the function and data relationship, which is called DAG.

I found %>% have a great nature than other languages, when I am using Airflow, a Python workflow secheduler, the process of describing DAG is so tedious and I think it can be done in R in an elegant way.

In that, I am seeking a way to catch the abstract grammar tree in a list object or two data frame, which called as graph frame, to plot the workflow using ggplot2. And the key problem is how to get the list object...need your help.

>pryr::call_tree
function (x, width = getOption("width")) 
{
    if (is.expression(x) || is.list(x)) {
        trees <- vapply(x, tree, character(1), width = width)
        out <- str_c(trees, collapse = "\n\n")
    }
    else {
        out <- tree(x, width = width)
    }
    cat(out, "\n")
}
<environment: namespace:pryr>

what I am trying

> abc <- function(x) {
+   if (is.expression(x) || is.list(x)) {
+     trees <- vapply(x, tree, character(1), width = width)
+     out <- str_c(trees, collapse = "\n\n")
+   }
+   else {
+     out <- tree(x, width = width)
+   }
+   return(out)
+ }
> abc(123+2123)
Error in abc(123 + 2123) : could not find function "tree"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant