Source (via sys.source()) and attach (attach) an R source file.

sourceAttach(file, pos=2,
             name = paste(abbreviate(gsub(fsep,"", dirname(file)),
                                     12, method="both.sides"),
                          basename(file), sep=fsep),
             keep.source = getOption("keep.source.pkgs"),
             warn.conflicts = TRUE)

Arguments

file

file name

pos

passed to attach()

name

character, with a smart default, passed to attach().

keep.source

logical, see sys.source().

warn.conflicts

logical, see attach.

Value

the return value of attach().

Author

Martin Maechler, 29 Jul 2011

See also

Examples

 sourceAttach(system.file("test-tools-1.R", package="Matrix", mustWork=TRUE))
#> Loading required package: tools
#> The following object is masked from package:sfsmisc:
#> 
#>     Sys.memGB
#> The following object is masked from package:base:
#> 
#>     %||%
 search() # shows the new "data base" at position 2
#>  [1] ".GlobalEnv"                  "optR4.4.1lRM/test-tools-1.R"
#>  [3] "package:tools"               "package:gmp"                
#>  [5] "package:lokern"              "package:MASS"               
#>  [7] "package:cluster"             "package:rpart"              
#>  [9] "package:sfsmisc"             "package:stats"              
#> [11] "package:graphics"            "package:grDevices"          
#> [13] "package:utils"               "package:datasets"           
#> [15] "package:methods"             "Autoloads"                  
#> [17] "tools:callr"                 "package:base"               
 ## look what it contains:
 ls.str(pos = 2)
#> %||% : function (x, orElse)  
#> S4_2list : function (obj)  
#> Sys.memGB : function (kind = "MemTotal", NA.value = 2.10201)  
#> add.simpleDimnames : function (m, named = FALSE)  
#> all.equal.X : function (x, y, except, tol = .Machine$double.eps^0.5, ...)  
#> all.slot.equal : function (x, y, ...)  
#> as.listS4 : function (obj)  
#> as.mat : function (m)  
#> assert.EQ : function (target, current, tol = if (showOnly) 0 else 1e-15, giveRE = FALSE, 
#>     showOnly = FALSE, ...)  
#> assert.EQ. : function (target, current, tol = if (showOnly) 0 else .Machine$double.eps^0.5, 
#>     giveRE = TRUE, showOnly = FALSE, ...)  
#> assert.EQ.Mat : function (M, M2, tol = if (showOnly) 0 else 1e-15, showOnly = FALSE, giveRE = FALSE, 
#>     ...)  
#> assert.EQ.mat : function (M, m, tol = if (showOnly) 0 else 1e-15, showOnly = FALSE, giveRE = FALSE, 
#>     ...)  
#> assertWarningAtLeast : function (expr, verbose = getOption("verbose"))  
#> chk.matrix : function (M)  
#> chkQR : function (a, y = seq_len(nrow(a)), a.qr = qr(a), tol = 1e-11, Qinv.chk = !sp.rank.def, 
#>     QtQ.chk = !sp.rank.def, verbose = getOption("Matrix.verbose", FALSE), 
#>     giveRE = verbose, quiet = FALSE)  
#> dnIdentical : function (x, y)  
#> dnIdentical3 : function (x, y, z)  
#> identical3 : function (x, y, z)  
#> identical4 : function (a, b, c, d)  
#> identical5 : function (a, b, c, d, e)  
#> identical6 : function (a, b, c, d, e, f)  
#> identical7 : function (a, b, c, d, e, f, g)  
#> is.EQ.mat : function (M1, M2, tol = 1e-15, dimnames = TRUE, ...)  
#> is.EQ.mat3 : function (M1, M2, M3, tol = 1e-15, dimnames = TRUE, ...)  
#> is.all.equal : function (x, y, tol = .Machine$double.eps^0.5, ...)  
#> is.all.equal3 : function (x, y, z, tol = .Machine$double.eps^0.5, ...)  
#> is.all.equal4 : function (x, y, z, u, tol = .Machine$double.eps^0.5, ...)  
#> isOrthogonal : function (x, tol = 1e-15)  
#> isValid : function (x, class)  
#> mkNA.0 : function (x)  
#> nCorrDigits : function (target, current, zeroDigs = 16)  
#> pkgRversion : function (pkgname)  
#> showProc.time : function (final = "\n", ind = TRUE)  
#> showSys.time : function (expr, ...)  
#> stopifnotValid : function (x, class)  
#> tryCatch.W.E : function (expr)