Unnest R calls

unnest_calls(.data, input, drop = TRUE)

Arguments

.data

A data frame

input

Input column that contains an R call or list of R calls to be split into individual functions

drop

logical. Whether the original input column should be dropped.

Value

The original data frame with an additional three columns:

  • line: the line number of the call

  • func: the name of the function called

  • args: a list of arguments

Examples

d <- read_rfiles(tidycode_example("example_plot.R")) # Unnest a model call d %>% unnest_calls(expr)
#> # A tibble: 14 x 4 #> file line func args #> <chr> <int> <chr> <list> #> 1 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 1 library <list [… #> 2 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 + <list [… #> 3 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 %>% <list [… #> 4 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 %>% <list [… #> 5 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 %>% <list [… #> 6 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 select <list [… #> 7 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 filter <list [… #> 8 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 ! <list [… #> 9 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 is.na <list [… #> 10 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 ! <list [… #> 11 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 is.na <list [… #> 12 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 ggplot <list [… #> 13 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 aes <list [… #> 14 /Users/lucymcgowan/wonderland/tidycode/inst/extdata… 2 geom_poi… <list [
# Unnest a model call and keep the call itself using the drop parameter d %>% unnest_calls(expr, drop = FALSE)
#> # A tibble: 14 x 5 #> file expr line func args #> <chr> <list> <int> <chr> <list> #> 1 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 1 library <list [… #> 2 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 + <list [… #> 3 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 %>% <list [… #> 4 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 %>% <list [… #> 5 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 %>% <list [… #> 6 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 select <list [… #> 7 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 filter <list [… #> 8 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 ! <list [… #> 9 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 is.na <list [… #> 10 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 ! <list [… #> 11 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 is.na <list [… #> 12 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 ggplot <list [… #> 13 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 aes <list [… #> 14 /Users/lucymcgowan/wonderland/tidycode/inst… <langua… 2 geom_po… <list [