getInputFiles: Find the file names that are read or written in R code

View source: R/getIOArgs.R

getInputFilesR Documentation

Find the file names that are read or written in R code

Description

These functions analyze R code to find the names of the files in R calls that read or write data or plots. The functions find all calls to functions known to read or write data or create file-based graphics output. One can identify the names of functions to be considered and also use findReadDataFuns, findWriteDataFuns, findGraphicsDevFuns to analyze other functions to see if they call these primitive functions and so include those functions as targets.

Usage

getInputFiles(x, lang = TRUE, ..., .funNames = getReadDataFuns(...))
getOutputFiles(x, lang = TRUE, ..., .funNames = getOutputDataFuns(...))
getGraphicsOutputFiles(x, lang = TRUE, ..., .funNames = getGraphicsDevFuns(...))

Arguments

x

a character vector of R file or directory names, an expression from parsing an R script, the output from getAllCalls or generally any R language objects.

lang

a logical value. If FALSE, only literal arguments are returned, basically, literal strings representing file names (but possibly also logical, integer or numeric values); if TRUE, expressions/language objects that are the arguments.

...

a collection of function = parameter-name(s) pairs specifying additional functions and their parameters that identify where a function is writing to a file/connection.

.funNames

the list of function-parameter(s) pairs identifying the functions writing to a file/connection.

Value

a character vector or list. Where the functions operate on literal file names, a string is returned. Where the call operates on a variable or call that is not known to be a constant, the (rstatic) language object is returned.

Author(s)

Duncan Temple Lang

See Also

findReadDataFuns, findWriteDataFuns, findGraphicsDevFuns

Examples

  f = system.file("sampleCode/inputFiles.R", package = "CodeAnalysis")
  getInputFiles(f)
  # includes a call to sprintf()

  getInputFiles(f, lang = FALSE)
  # NA in place of the sprintf()


## Not run: 
    # Project from git@github.com:mespe/Variety_trial_analysis.git
  ff = list.files("~/Book/ExploreCode/Variety_trial_analysis/code", pattern = "\.R$", full = TRUE)
  inp = lapply(ff, getInputFiles, FALSE)
  names(inp) = basename(ff)

  out = lapply(ff, getOutputFiles, FALSE)
  names(out) = basename(ff)

  grout = lapply(ff, getGraphicsOutputFiles, FALSE)
  names(grout) = basename(ff)

## End(Not run)

duncantl/CodeAnalysis documentation built on Feb. 21, 2024, 10:49 p.m.