pkgCodeInfo: Information about code in an R file or directory of R files

pkgCodeInfoR Documentation

Information about code in an R file or directory of R files

Description

These functions analyze the code in an R file or a collection of R files in a directory (not necessarily a formal package) and returns a description summarizing the top-level objects in the code, i.e., functions, methods, variables.

It ignores code in if(FALSE) expressions.

Usage

pkgCodeInfo(dir, rfiles = getRFiles(dir, recursive = recursive), recursive = TRUE)
fileCodeInfo(file, code = parse(file), addClass = TRUE)

Arguments

dir

the path to a directory containing the R code, or a file

rfiles

the full paths to the files to process, useful if one only wants to process a subset of the files in the directory or combine files from multiple directories.

recursive

a logical value passed to list.files and controls whether we find R code files in sub-directories.

file

the full path to the R file containing the code to process

code

the R code to analyze

addClass

a logical value indicating whether to add the FileCodeInfo class to the resulting data.frame.

Value

A data.frame with 6 elements:

name

the name of the top-level object

type

the R type

op

the top-level operation, often '=' or '<-', but also calls to Vectorize, setAs, setGeneric, ...

expr

a list of the R code/language objects

file

the name of the file in which the expression is located

index

the index of that top-level expression in that file.

Author(s)

Duncan Temple Lang

Examples

  dir = system.file("sampleCode", package = "CodeAnalysis")
  info = pkgCodeInfo(dir)
  dim(info)
  table(info$op)
  table(info$file)

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