Finds all 'srcfile' objects generated by source() in all call frames. This makes it possible to find out which files are currently scripted by source().

# S3 method for default
findSourceTraceback(...)

Arguments

...

Not used.

Value

Returns a named list of srcfile() objects and/or

character strings. The names of the list entries corresponds to the 'filename' value of each corresponding 'srcfile' object. The returned list is empty if source() was not called.

Author

Henrik Bengtsson

See also

See also sourceutils.

Examples

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Create two R script files where one source():s the other
# and both lists the traceback of filenames source():d.
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
path <- tempdir()
pathnameA <- Arguments$getWritablePathname("foo.R", path=path)
pathnameB <- Arguments$getWritablePathname("bar.R", path=path)

code <- 'cat("BEGIN foo.R\n")'
code <- c(code, 'print(findSourceTraceback());')
code <- c(code, sprintf('source("%s");', pathnameB))
code <- c(code, 'cat("END foo.R\n")')
code <- paste(code, collapse="\n")
cat(file=pathnameA, code)

code <- 'cat("BEGIN bar.R\n")'
code <- c(code, 'x <- findSourceTraceback();')
code <- c(code, 'print(x);')
code <- c(code, 'cat("END bar.R\n")')
code <- paste(code, collapse="\n")
cat(file=pathnameB, code)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Source the first file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
source(pathnameA, echo=TRUE)
#> 
#> > cat("BEGIN foo.R\n")
#> BEGIN foo.R
#> 
#> > print(findSourceTraceback())
#> $`/tmp/henrik/RtmpAr1qq8/foo.R`
#> [1] "/tmp/henrik/RtmpAr1qq8/foo.R"
#> 
#> 
#> > source("/tmp/henrik/RtmpAr1qq8/bar.R")
#> BEGIN bar.R
#> $`/tmp/henrik/RtmpAr1qq8/bar.R`
#> [1] "/tmp/henrik/RtmpAr1qq8/bar.R"
#> 
#> $`/tmp/henrik/RtmpAr1qq8/foo.R`
#> [1] "/tmp/henrik/RtmpAr1qq8/foo.R"
#> 
#> END bar.R
#> 
#> > cat("END foo.R\n")
#> END foo.R