diff --git a/R/httpget_package_file.R b/R/httpget_package_file.R index 91c67bc0..d39467af 100644 --- a/R/httpget_package_file.R +++ b/R/httpget_package_file.R @@ -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="/"))); } diff --git a/R/httpget_package_r.R b/R/httpget_package_r.R index ecf5b066..837a3f82 100644 --- a/R/httpget_package_r.R +++ b/R/httpget_package_r.R @@ -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") + ); + }); } diff --git a/R/httpget_session_graphics.R b/R/httpget_session_graphics.R index ae51f3cd..0f3d28fe 100644 --- a/R/httpget_session_graphics.R +++ b/R/httpget_session_graphics.R @@ -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")); diff --git a/R/httpget_session_r.R b/R/httpget_session_r.R index 6e696b65..1a2ad89d 100644 --- a/R/httpget_session_r.R +++ b/R/httpget_session_r.R @@ -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(); diff --git a/R/httpget_user_library.R b/R/httpget_user_library.R index 688f9ca9..26d6e30b 100644 --- a/R/httpget_user_library.R +++ b/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); + }); } diff --git a/R/onLoad.R b/R/onLoad.R index 7482bd65..c9740744 100644 --- a/R/onLoad.R +++ b/R/onLoad.R @@ -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 diff --git a/inst/config/defaults.conf b/inst/config/defaults.conf index 47b43c46..6071214d 100644 --- a/inst/config/defaults.conf +++ b/inst/config/defaults.conf @@ -14,6 +14,5 @@ "appspaths" : "/usr/local/lib/opencpu/apps-library", "repos" : "http://cran.rstudio.com", "tmpdir" : "/tmp", - "libpaths" : [], "preload" : [] }