[Distr-commits] r784 - branches/distr-2.4/pkg/SweaveListingUtils/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Feb 3 17:44:14 CET 2012


Author: ruckdeschel
Date: 2012-02-03 17:44:13 +0100 (Fri, 03 Feb 2012)
New Revision: 784

Modified:
   branches/distr-2.4/pkg/SweaveListingUtils/R/SweaveListingUtils.R
Log:
wrapped calls to readLines in SourceFromRForge in try() in order to avoid errors when R-forge site is down (triggered by B. Ripley's mail from Feb 1, 2012).

Modified: branches/distr-2.4/pkg/SweaveListingUtils/R/SweaveListingUtils.R
===================================================================
--- branches/distr-2.4/pkg/SweaveListingUtils/R/SweaveListingUtils.R	2012-01-17 16:12:40 UTC (rev 783)
+++ branches/distr-2.4/pkg/SweaveListingUtils/R/SweaveListingUtils.R	2012-02-03 16:44:13 UTC (rev 784)
@@ -226,7 +226,8 @@
   if(is.null(.CacheFiles[[base.URL]])){
     .CacheLength <<- .CacheLength + 1
     url.connection <- url(base.URL) 
-    RL <- readLines(url.connection)
+    RL <- try(readLines(url.connection),silent=TRUE)
+    if(is(RL,"try-error")) return(character(0))
     close(url.connection)
     .CacheFiles[[base.URL]] <<- RL
   }
@@ -243,21 +244,23 @@
    RL <- readSourceFromRForge(PKG, TYPE, FILENAME, PROJECT, 
                               fromRForge = fromRForge, base.url = base.url)
    lR <- length(RL)
-   from <- if(missing(from)) 1 else {if(is.numeric(from))
-                                        max(from-offset.before,1)
-                                     else {if(length(gr0 <- grep(from,RL, ...)))
+   if(lR>0){
+      from <- if(missing(from)) 1 else {if(is.numeric(from))
+                                            max(from-offset.before,1)
+                                        else {if(length(gr0 <- grep(from,RL, ...)))
                                             max(gr0[1]-offset.before,1) else lR
                                           }
                                     }
-   to <- if(missing(to)) lR else {if(is.numeric(to))
+      to <- if(missing(to)) lR else {if(is.numeric(to))
                                         min(to+offset.after,lR)
                                      else {if(length(gr1<-grep(to,RL[from:lR], ...)))
-                                            min(from+gr1[1]-1+offset.after,lR)
+                                              min(from+gr1[1]-1+offset.after,lR)
                                            else 0
                                            }
-                                 }
-   if(to>=from) return(list(text=RL[from:to], lines=c(from,to)))
-   return(invisible())
+                                    }
+      if(to>=from) return(list(text=RL[from:to], lines=c(from,to)))
+   }
+   return(invisible(NULL))
 }
 
 #------------------------------------------------------------------------------
@@ -307,6 +310,7 @@
                         fromRForge = fromRForge, base.url = base.url,dots))
    }
    erg <- lapply(argL, function(x)  do.call(copySourceFromRForge, args = c(x)))
+   if(length(erg)==0) return(invisible(NULL))
    RL <- lapply(erg, function(x) x$text)
    lineNr <- lapply(erg, function(x) x$lines)
    lR <- lapply(RL, length)



More information about the Distr-commits mailing list