knitr::opts_chunk$set(echo = TRUE) options(keep.source = TRUE)
library(straw) plot_ast <- . %>% parse(text = .) %>% create_parse_graph(type = "ast") %>% tbl_to_cyto() %>% cytoscape_dagre(width = "100%") plot_parse <- . %>% parse(text = .) %>% create_parse_graph() %>% tbl_to_cyto() %>% cytoscape_dagre(width = "100%")
expr <- parse(text = "function(a = 1) {2}") # function node consists of 3 entries # 1. function keyword # 2. function args (a pairlist) # 3. function body (expression | anything) fun <- expr[[1]] # the pairlist is the trickiest to handle, # since in the parse tree each arg is a node fun[[2]]
g <- create_parse_graph(expr) g_ast <- create_parse_graph(expr, type = 'ast') match_expr(g, g_ast, g[2,], g_ast[2,])
expr <- "function(a, b = 1) 2"
=
operatorNeed to dig down in AST
expr2 <- "a + 1= 1 = 2 = 3; 1 + 1"
expr3 <- " a = 1 + 2 b = 3 "
p3 <- parse(text = expr3) p3[[1]] pd <- create_parse_graph(p3) pd[pd$children[[1]],]
expr4 <- "function(a) b = 1"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.