Skip to content

locally defined functions that call themselves #41

@clarkfitzg

Description

@clarkfitzg

If a function is defined locally and calls itself (so it's recursive), then ideally CodeDepends should identify that the usage of the function is local, and not from a package. This came up for me in tryCatch, specifically getInputs(tryCatch)[[3L]] where tryCatchList defines and uses itself. One can use Recall to achieve the same result.

Here's a minimal example:

add_123 = function(x){
    add = function(y, ...){
        if(!missing(y)){
            y + add(...)
            #y + Recall(...)  # Alternatively
        } else 0
    }
    add(x, 1, 2, 3)
}

info = getInputs(add_123)

info[[3]]@functions["add"]  # FALSE, should be TRUE

info[[4]]@functions["add"]  # TRUE, as expected

I can work around this behavior by checking if the name of the function used is also an output.

The documentation for the functions slot from getInputs states:

Note that this is not recursive.

I understand this to mean that it doesn't recursively look at all functions called.

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