Skip to content

Question: how to apply getInputs() recursively? #51

Description

@MatthieuStigler

I am interested in using getInputs() recursively, so that for each function within a call, I get the output of getInputs(). The problem is that otherwise, if a call contains multiple @function, I will not know which @input or @strings belongs to it.

I see that there is a mention Note that this is not recursive. in the help file, but I was hoping someone might have a hint on how to make it recursive? The idea is that the output would be a list of getInput(), for each function?

Thanks!

Here would be two example where it is not clear to which function each input or string belong to?

library(CodeDepends)
expr <- quote(if(TRUE) {fun1(inp1)} else {fun2(input2)})
getInputs(expr)
#> An object of class "ScriptNodeInfo"
#> Slot "files":
#> character(0)
#> 
#> Slot "strings":
#> character(0)
#> 
#> Slot "libraries":
#> character(0)
#> 
#> Slot "inputs":
#> [1] "inp1"   "input2"
#> 
#> Slot "outputs":
#> character(0)
#> 
#> Slot "updates":
#> character(0)
#> 
#> Slot "functions":
#>   if    { fun1 fun2 
#>   NA   NA   NA   NA 
#> 
#> Slot "removes":
#> character(0)
#> 
#> Slot "nsevalVars":
#> character(0)
#> 
#> Slot "sideEffects":
#> character(0)
#> 
#> Slot "code":
#> if (TRUE) {
#>     fun1(inp1)
#> } else {
#>     fun2(input2)
#> }
expr <- quote(if(file.exists("file.csv")) {read.csv("file2.csv")} else {write.csv("file2.csv")})
getInputs(expr)
#> An object of class "ScriptNodeInfo"
#> Slot "files":
#> character(0)
#> 
#> Slot "strings":
#> [1] "file.csv"  "file2.csv"
#> 
#> Slot "libraries":
#> character(0)
#> 
#> Slot "inputs":
#> character(0)
#> 
#> Slot "outputs":
#> character(0)
#> 
#> Slot "updates":
#> character(0)
#> 
#> Slot "functions":
#>          if file.exists           {    read.csv   write.csv 
#>          NA          NA          NA          NA          NA 
#> 
#> Slot "removes":
#> character(0)
#> 
#> Slot "nsevalVars":
#> character(0)
#> 
#> Slot "sideEffects":
#> character(0)
#> 
#> Slot "code":
#> if (file.exists("file.csv")) {
#>     read.csv("file2.csv")
#> } else {
#>     write.csv("file2.csv")
#> }

Created on 2025-02-18 with reprex v2.1.1

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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