Skip to content

Commit

Permalink
avoid .libPaths() because windows sux
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed Jul 20, 2013
1 parent 4e2b1d7 commit 21b736d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 55 deletions.
9 changes: 6 additions & 3 deletions R/httpget_package_file.R
Expand Up @@ -5,8 +5,11 @@ httpget_package_file <- function(pkgpath, requri){
reqlib <- dirname(pkgpath);

#try to load package from reqlib, but otherwise other paths are OK
.libPaths(c(reqlib, .libPaths()));
library(reqpackage, character.only=TRUE)
inlib(reqlib,{
library(reqpackage, character.only=TRUE);
httpget_file(file.path(pkgpath, paste(requri, collapse="/")));
});
} else {
httpget_file(file.path(pkgpath, paste(requri, collapse="/")));
}
httpget_file(file.path(pkgpath, paste(requri, collapse="/")));
}
46 changes: 23 additions & 23 deletions R/httpget_package_r.R
Expand Up @@ -4,27 +4,27 @@ httpget_package_r <- function(pkgpath, requri){
reqpackage <- basename(pkgpath);
reqlib <- dirname(pkgpath);

#try to load package from reqlib, but otherwise other paths are OK
#Use .libPaths because we want to save the library path after evaluation.
.libPaths(c(reqlib, .libPaths()));
library(reqpackage, character.only=TRUE)

#reqhead is function/object name
reqobject <- head(requri, 1);
reqformat <- requri[2];

if(!length(reqobject)){
res$checkmethod();
res$sendlist(ls(paste("package", reqpackage, sep=":")));
}

#Get object. Throws error if object does not exist.
myobject <- get(reqobject, paste("package", reqpackage, sep=":"), inherits=FALSE);

#return object
switch(req$method(),
"GET" = httpget_object(myobject, reqformat, reqobject),
"POST" = execute_function(myobject, tail(requri, -1), reqobject),
stop("invalid method")
);
#Package has to be loaded from reqlib, but dependencies might be loaded from global libs.
inlib(reqlib,{
library(reqpackage, lib.loc=reqlib, character.only=TRUE);
#reqhead is function/object name
reqobject <- head(requri, 1);
reqformat <- requri[2];

if(!length(reqobject)){
res$checkmethod();
res$sendlist(ls(paste("package", reqpackage, sep=":")));
}
#Get object. Throws error if object does not exist.
myobject <- get(reqobject, paste("package", reqpackage, sep=":"), inherits=FALSE);
#return object
switch(req$method(),
"GET" = httpget_object(myobject, reqformat, reqobject),
"POST" = execute_function(myobject, tail(requri, -1), reqobject),
stop("invalid method")
);
});
}
32 changes: 18 additions & 14 deletions R/httpget_session_graphics.R
Expand Up @@ -7,21 +7,25 @@ httpget_session_graphics <- function(filepath, requri){
#try to use old libraries
libfile <- file.path(filepath, ".Rlibs");
if(file.exists(libfile)){
.libPaths(readRDS(libfile));
}

#graphics packages sometimes need to be reloaded
infofile <- file.path(filepath, ".RInfo");
if(file.exists(infofile)){
myinfo <- readRDS(infofile);
allpackages <- c(names(myinfo$otherPkgs), names(myinfo$loadedOnly));
if("ggplot2" %in% allpackages){
getNamespace("ggplot2");
customlib <- readRDS(libfile);
} else {
customlib <- NULL;
}

#graphics packages sometimes need to be reloaded
inlib(customlib, {
infofile <- file.path(filepath, ".RInfo");
if(file.exists(infofile)){
myinfo <- readRDS(infofile);
allpackages <- c(names(myinfo$otherPkgs), names(myinfo$loadedOnly));
if("ggplot2" %in% allpackages){
getNamespace("ggplot2");
}
if("lattice" %in% allpackages){
getNamespace("lattice");
}
}
if("lattice" %in% allpackages){
getNamespace("lattice");
}
}
});

#load data
myeval <- readRDS(sessionfile <- file.path(filepath, ".REval"));
Expand Down
14 changes: 9 additions & 5 deletions R/httpget_session_r.R
Expand Up @@ -7,14 +7,18 @@ httpget_session_r <- function(filepath, requri){
#try to use old libraries
libfile <- file.path(filepath, ".Rlibs");
if(file.exists(libfile)){
.libPaths(readRDS(libfile));
customlib <- readRDS(libfile);
} else {
customlib <- NULL;
}

#reload packages
infofile <- file.path(filepath, ".RInfo");
if(file.exists(infofile)){
loadsessioninfo(infofile);
}
inlib(customlib, {
infofile <- file.path(filepath, ".RInfo");
if(file.exists(infofile)){
loadsessioninfo(infofile);
}
});

#load session
sessionenv <- new.env();
Expand Down
9 changes: 5 additions & 4 deletions R/httpget_user_library.R
@@ -1,8 +1,9 @@
httpget_user_library <- function(username, requri){
#append user home library to path
homelib <- userlibpath(username);
.libPaths(homelib);

#load package from homelib (dependencies can still be loaded from site library)
httpget_library(homelib, requri);

#load package from homelib (dependencies can still be loaded from site library)
inlib(homelib, {
httpget_library(homelib, requri);
});
}
5 changes: 0 additions & 5 deletions R/onLoad.R
Expand Up @@ -35,11 +35,6 @@ packagename = "";

if(.Platform$OS.type != "windows"){
Sys.setlocale(category='LC_ALL', 'en_US.UTF-8');

#add non-system opencpu libraries
if(length(config("libpaths")) > 0){
.libPaths(unlist(config("libpaths")));
}
}

#preload libraries
Expand Down
1 change: 0 additions & 1 deletion inst/config/defaults.conf
Expand Up @@ -14,6 +14,5 @@
"appspaths" : "/usr/local/lib/opencpu/apps-library",
"repos" : "http://cran.rstudio.com",
"tmpdir" : "/tmp",
"libpaths" : [],
"preload" : []
}

0 comments on commit 21b736d

Please sign in to comment.