[Swift-commit] r4327 - SwiftApps/SwiftR/Swift/R

tga at ci.uchicago.edu tga at ci.uchicago.edu
Fri Apr 8 15:59:22 CDT 2011


Author: tga
Date: 2011-04-08 15:59:21 -0500 (Fri, 08 Apr 2011)
New Revision: 4327

Modified:
   SwiftApps/SwiftR/Swift/R/Library.R
Log:
Fixed argument hadnling of swiftDetach.


Modified: SwiftApps/SwiftR/Swift/R/Library.R
===================================================================
--- SwiftApps/SwiftR/Swift/R/Library.R	2011-04-08 20:52:54 UTC (rev 4326)
+++ SwiftApps/SwiftR/Swift/R/Library.R	2011-04-08 20:59:21 UTC (rev 4327)
@@ -9,13 +9,14 @@
     subpackname <- substitute(packname)
     # Check to see if it is a string, if it is not a string
     # then we will deparse it to get the expression text
-    if (!is.character(subpackname) && is.name(subpackname)) {
-        # Maybe library was provided unquoted
-    
-        packname <- deparse(subpackname)
+    if (!is.character(subpackname)) {
+        if (is.name(subpackname)) {
+            # Maybe library was provided unquoted
+            packname <- deparse(subpackname)
+        }
     }
 
-    if (!packname %in% installed.packages()) {
+    if (!(packname %in% installed.packages())) {
         # Warn users in case they made a typo
         warning(paste("Package", packname, 
                 "was not a installed package in this instance of R,", 
@@ -61,32 +62,42 @@
     options(.swift.packages=plist)
 }
 
-swiftDetach <- function (name) {
+sstartsWith <- function (str, prefix) {
+    substr(str, 1, nchar(prefix)) == prefix
+}
+
+swiftDetach <- function (packname) {
     # name is an string or identifier such as "package:OpenMx",
     #   following the same pattern as the built in R detach() function
     # Detaches a library from workers and ensures that it will no longer be 
-    # imported.  Note that the effect on dependent imports is a little
+    # imported.  
+    
+    # Caveat: the effect on dependent imports is a little
     # messy and behaves differently on existing and new workers.  
     # If package A requires package B, and we import A on a worker,
     # package B will also be imported on the worker.  By detaching package A
     # we don't also detach B.  This contrasts to a fresh worker, where
     # package B will not be imported.
-    subname <- substitute(name)
+
     # Check to see if it is a string, if it is not a string
+    subpackname <- substitute(packname)
     # then we will deparse it to get the expression text
-    if (!is.character(subname) && is.name(subname)) {
-        # Maybe library was provided unquoted
-    
-        name <- deparse(subname)
+    if (!is.character(subpackname)) {
+        # Check to see if symbol name has package: prefix
+        deparsed <- deparse(subpackname)
+        if (sstartsWith(deparsed, "package:")) {
+            # Maybe library was provided unquoted
+            packname <- deparsed
+        }
     }
     
     #TODO: remove from options(".swift.packages")
     # Scan through list and remove any attach or detach of this name
     # add a detach cmd to the end
-    if (substr(name, 1, 8) != "package:")
+    if (!sstartsWith(packname, "package:"))
         stop("Can only detach packages.  Package must be specified as package:PackageName")
     # Get bit after "package:"
-    packname = substr(name, 9, nchar(name))
+    packname = substr(packname, 9, nchar(packname))
     plist = getOption(".swift.packages")
     if (is.null(plist)) {
         plist = list()




More information about the Swift-commit mailing list