[Swift-commit] r4056 - in SwiftApps/SwiftR/Swift: . R

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Thu Feb 3 14:19:49 CST 2011


Author: tga
Date: 2011-02-03 14:19:49 -0600 (Thu, 03 Feb 2011)
New Revision: 4056

Modified:
   SwiftApps/SwiftR/Swift/NAMESPACE
   SwiftApps/SwiftR/Swift/R/Library.R
Log:
Added swiftDetachAll() function to reset the libraries loaded on worker machines.


Modified: SwiftApps/SwiftR/Swift/NAMESPACE
===================================================================
--- SwiftApps/SwiftR/Swift/NAMESPACE	2011-02-03 20:00:40 UTC (rev 4055)
+++ SwiftApps/SwiftR/Swift/NAMESPACE	2011-02-03 20:19:49 UTC (rev 4056)
@@ -4,6 +4,7 @@
 export(swiftShutdown)
 export(swiftLibrary)
 export(swiftDetach)
+export(swiftDetachAll)
 
 export(runAllSwiftTests)
 export(basicSwiftTest)

Modified: SwiftApps/SwiftR/Swift/R/Library.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Library.R	2011-02-03 20:00:40 UTC (rev 4055)
+++ SwiftApps/SwiftR/Swift/R/Library.R	2011-02-03 20:19:49 UTC (rev 4056)
@@ -31,11 +31,32 @@
     }
     # Add the library command to the end of the list of commands to be 
     # executed in slave R instances
-    plist[[length(plist) + 1]] <- c("library", packname)
+        plist[[length(plist) + 1]] <- c("library", packname)
     
     options(.swift.packages=plist)
 }
 
+swiftDetachAll <- function () {
+    # Detaches all packages previously loaded through swiftLibrary
+    plist = getOption(".swift.packages")
+    if (is.null(plist)) {
+        # Nothing added before
+        return
+    }
+    # replace all c("library", libname) entries in list with:
+    #   c("detach", libname)
+    plist = lapply(plist, 
+            function (ent) {
+                if (ent[1] == "library") {
+                    c("detach", ent[2])
+                }
+                else {
+                    # already detached
+                    ent
+                }
+            })
+    options(.swift.packages=plist)
+}
 
 swiftDetach <- function (name) {
     # name is an string or identifier such as "package:OpenMx",




More information about the Swift-commit mailing list