Skip to content

Find functions passed as arguments #13

@rjake

Description

@rjake

This is the use case I mentioned at the RStudio conference. I'd like to find functions called as arguments in apply functions or in something like switch()

file_lines <- "
  sapply(mtcars, min)

  agg <- function(x, fun) {
    fn <- 
      switch(
        fun, 
        avg = mean,
        total = sum
      )
    
    fn(x, na.rm = TRUE)
  }

agg(1:3, 'total')
"

file_output <- tempfile(fileext = ".R")
writeLines(file_lines, file_output)
# A tibble: 4 x 2
  funs   pkgs     
  <chr>  <chr>    
1 sapply base     
2 switch base     
3 fn     (unknown)
4 agg    (unknown)

I am expecting to see min, mean and sum in the mix

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions