comparison R/rdyncall/R/dynport.R @ 0:0cfcc391201f

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:26:28 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:0cfcc391201f
1 # Project: rdyncall
2 # File: R/dynports.R
3 # Description: repository for multi-platform bindings to binary components.
4 # Author: Daniel Adler <dadler@uni-goettingen.de>
5
6 dynport <- function(portname, portfile=NULL, repo=system.file("dynports", package="rdyncall"))
7 {
8 # literate portname string
9 portname <- as.character(substitute(portname))
10 if (missing(portfile))
11 {
12 # search for portfile
13 portfile <- file.path( repo, paste(portname,".R",sep="") )
14 if ( !file.exists(portfile) ) portfile <- file.path( repo, paste(portname,".json",sep="") )
15 if ( !file.exists(portfile) ) stop("dynport '", portname, "' not found.")
16 }
17 loadDynportNamespace(portname, portfile)
18 }
19
20 loadDynportNamespace <- function(name, portfile, do.attach=TRUE)
21 {
22 name <- as.character(name)
23 portfile <- as.character(portfile)
24 if (do.attach) {
25 envname <- paste("dynport", name, sep=":")
26 if ( envname %in% search() ) return()
27 env <- new.env()
28 sys.source(portfile, envir=env)
29 attach(env, name=envname)
30 } else {
31 env <- new.env()
32 sys.source(portfile, envir=env)
33 return(env)
34 }
35 }
36