# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# 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
")';
code <- c(code, 'print(findSourceTraceback());');
code <- c(code, sprintf('source("%s");', pathnameB));
code <- c(code, 'cat("END foo.R
")');
code <- paste(code, collapse="");
cat(file=pathnameA, code);
code <- 'cat("BEGIN bar.R
")';
code <- c(code, 'print(findSourceTraceback());');
code <- c(code, 'cat("END bar.R
")');
code <- paste(code, collapse="");
cat(file=pathnameB, code);
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Source the first file
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
source(pathnameA, echo=TRUE);
Run the code above in your browser using DataLab