Skip to contents

When a script errors with object 'X' not found, the fix is usually to run the script that defines X first. This scans each file for top-level variable assignments — x <- ..., x = ..., x <<- ..., and assign("x", ...) — so an undefined-variable error can be matched to the file that would supply it (see the module's corrective re-run). Only assignments at the start of a (comment-free) line are taken, which approximates "top level": an assignment indented inside a function/for body is not a global the next sourced script would see, and taking it would create false ordering edges.

Usage

repro_defined_vars(code_text_list)

Arguments

code_text_list

a named list of code-text character vectors, one per file (names are the file_names)

Value

a data frame with file_name and a list-column defines (character vector of variable names each file assigns at top level).

Examples

code <- list(prep.R = c("x <- 1", "y <- x + 1"), analysis.R = "print(y)")
repro_defined_vars(code)
#>    file_name defines
#> 1     prep.R    x, y
#> 2 analysis.R