I fully sympathize with @Dirk's answer. The small overhead of creating a minimal package seems to be appropriate for the "standard way."
However, one thing that came to mind is the source local argument, which allows you to enter the source code into the environment , which can be used as a namespace, for example
assign(module, new.env(parent=baseenv()), envir=topenv()) source(filename, local=get(module, topenv()), chdir = TRUE)
To access these imported environments using simple syntax, give these import environments a new class (say, โimportโ) and create :: generic, the default getExportedValue if pkg does not exist.
import <- function (module) { module <- as.character(substitute(module))
Update
The following is a safer option that prevents errors if the downloaded package contains an object with the same name as the package that is accessed using :: .
'::' <- function(pkg, name) { pkg.chr <- as.character(substitute(pkg)) name.chr <- as.character(substitute(name)) if (exists(pkg.chr)) { if (class(pkg) == 'import') return(get(name.chr, pkg)) } getExportedValue(pkg.chr, name.chr) }
This will give the correct result, say if you downloaded data.table and subsequently tried to access one of your objects using :: .
Matthew Plourde Apr 03 2018-12-14T00: 00Z
source share