Skip to contents

Get files referenced in code

Usage

code_file_refs(
  code_text,
  lang = c("R", "Python", "SPSS", "SAS", "Stata", "Mplus", "MATLAB"),
  include_writes = FALSE
)

Arguments

code_text

the code text for a single file

lang

the language (we only currently handle R, Python, SPSS, SAS, Stata, Mplus, MATLAB)

include_writes

also return files the code writes (R only). Off by default: callers that ask "which referenced inputs are missing from the repository?" (e.g. code_check) must not see a written file as a missing input. repro_file_io() turns this on so a file produced by one script can be recognised as the input another script consumes.

Value

a vector of files that are referenced in the code

Examples

code_text <- c(
  'source("functions.R")',
  'a <- "bread"',
  'b <- read.csv("file.csv")'
)
code_file_refs(code_text, "R")
#> [1] "functions.R" "file.csv"