| 1 |
##' @title "Source + Attach" an R source file |
| 2 |
##' @author Martin Maechler, 29 Jul 2011 |
| 3 |
sourceAttach <- function(file, pos = 2, |
| 4 |
name = paste(abbreviate(gsub(fsep, "", dirname(file)), 12, |
| 5 |
method="both.sides"), |
| 6 |
basename(file), sep=fsep), |
| 7 |
keep.source = getOption("keep.source.pkgs"), |
| 8 |
warn.conflicts = TRUE) |
| 9 |
{ |
| 10 |
ENV <- new.env() |
| 11 |
sys.source(file, envir = ENV, keep.source = keep.source)# also checks file |
| 12 |
fsep <- .Platform$file.sep # for default 'name' : |
| 13 |
## mini-obfuscation: this *IS* a legitimate use of attach()! |
| 14 |
A <- attach |
| 15 |
A(ENV, pos=pos, name=name, warn.conflicts=warn.conflicts) |
| 16 |
} |