getSourceInfo | R Documentation |
This function and its methods construct the
graph matrix identifying which other R files each R file
source
s.
This is useful when analyzing the scripts in a project
to determine the relationships between them.
getSourceInfo(x, recursive = TRUE, ...)
x |
the R code to process. This cane be the name of a file, the parsed code, an expression. |
recursive |
a logical value. If |
... |
additional arguments passed to methods. Currently not used. |
a 2-column data.frame with each row containing the name of the R file that sources the file given in the second column.
If recursive
is TRUE
, getSourceInfo
each file will have <n>
rows in the result
where <n>
is the number of files that the file source()
s.
This will be 0 if the file A does not source()
any other files.
If a file sourced by one file doesn't exist, we don't know
if it source()
s any other files and so add NA.
This allows the caller to see all files that are intended to be source()
d
and then check which exist (rather than omitting these files from the result.)
Duncan Temple Lang
findCallsTo
f = system.file("sampleCode/source.R", package = "CodeAnalysis")
a = getSourceInfo(f, FALSE)
a
b = getSourceInfo(f)
b
## 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)
src = lapply(ff, getSourceInfo)
names(src) = basename(ff)
src = src[ sapply(src, nrow) > 0 ]
library(igraph)
tmp = src$temp_analysis
tmp = tmp[!is.na(tmp$sourced), ]
tmp$from = basename(tmp$from)
g = graph_from_data_frame(tmp)
plot(g)
# All the files and what they source combined
tmp2 = do.call(rbind, src)
tmp2$from = basename(tmp2$from)
tmp2 = tmp2[!is.na(tmp2$sourced), ]
plot(graph_from_data_frame(tmp2))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.