
Extract the files a script reads, writes, and sources
Source:R/reproducibility_check.R
repro_file_io.RdA thin wrapper that runs the static reference scans over each code file and
returns the per-file read / write / source basenames repro_run_order()
needs. Reads/writes come from code_file_refs() split by call type; sources
from a scan for source() (R only — see lang below). All returned as
lowercased basenames.
Arguments
- code_text_list
a named list of code-text character vectors, one per file (names are the file_names), OR a named list of such lists when files are in more than one language (see
lang)- lang
the language each element of
code_text_listis in: either a single string applied to every file (default"R"), or a named character vector keyed by file_name for a mixed-language set. Python has nosource()-equivalent for reusing a SIBLING analysis script by relative path (its code-reuse mechanism,import, names an installed module, not a local file run_order must sequence), sosourcesis always empty for a Python file;open(..., "w"/"a"/...)is classified as a write only when that same line's own mode argument says so (a bareopen(x)defaults to Python's own read mode and is otherwise ambiguous between the two).
Value
a data frame with file_name and list-columns reads, writes,
sources (each a character vector of basenames).
Examples
code <- list(clean.R = c("d <- read.csv('raw.csv')", "write.csv(d, 'clean.csv')"),
analysis.R = c("source('clean.R')", "d <- read.csv('clean.csv')"))
io <- repro_file_io(code)
io$reads
#> [[1]]
#> [1] "raw.csv"
#>
#> [[2]]
#> [1] "clean.csv"
#>
io$writes
#> [[1]]
#> [1] "clean.csv"
#>
#> [[2]]
#> character(0)
#>