[Sciviews-commits] r215 - in pkg/svMisc: . R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Oct 26 08:01:30 CET 2009


Author: phgrosjean
Date: 2009-10-26 08:01:29 +0100 (Mon, 26 Oct 2009)
New Revision: 215

Modified:
   pkg/svMisc/DESCRIPTION
   pkg/svMisc/NEWS
   pkg/svMisc/R/descFun.R
   pkg/svMisc/R/isHelp.R
Log:
Temporary hack for index.search() in isHelp() and descFun() in svMisc package

Modified: pkg/svMisc/DESCRIPTION
===================================================================
--- pkg/svMisc/DESCRIPTION	2009-10-26 06:16:13 UTC (rev 214)
+++ pkg/svMisc/DESCRIPTION	2009-10-26 07:01:29 UTC (rev 215)
@@ -4,8 +4,8 @@
 Imports: utils, methods
 Depends: R (>= 2.6.0), tools
 Description: Supporting functions for the GUI API (various utilitary functions)
-Version: 0.9-55
-Date: 2009-10-11
+Version: 0.9-56
+Date: 2009-10-26
 Author: Philippe Grosjean, Romain Francois & Kamil Barton
 Maintainer: Philippe Grosjean <phgrosjean at sciviews.org>
 License: GPL (>= 2)

Modified: pkg/svMisc/NEWS
===================================================================
--- pkg/svMisc/NEWS	2009-10-26 06:16:13 UTC (rev 214)
+++ pkg/svMisc/NEWS	2009-10-26 07:01:29 UTC (rev 215)
@@ -1,10 +1,17 @@
 = svMisc News
 
+== Changes in svMisc 0.9-56
+
+* Temporary code to disable index.search() in devel R 2.11 in isHelp() and
+  descFun().
+
+
 == Changes in svMisc 0.9-55
 
 * Implement descArgs using the new help system (parse_Rd), this eliminates
   the need for the workaround of version 0.9-54
 
+
 == Changes in svMisc 0.9-54
 
 * Cosmetic changes in Rd files to make them compatible with R 2.11 (devel). A

Modified: pkg/svMisc/R/descFun.R
===================================================================
--- pkg/svMisc/R/descFun.R	2009-10-26 06:16:13 UTC (rev 214)
+++ pkg/svMisc/R/descFun.R	2009-10-26 07:01:29 UTC (rev 215)
@@ -9,6 +9,13 @@
 	if (length(AllTopics) == 0) return("")
 	res <- character()
 	for (i in 1:length(fun)) {
+		# index.search() will not be visible any more and will have different
+		# arguments in R 2.11... and it is DEPRECATED in R 2.10
+		# => need to use a different code here!!!
+		# This is a temporary hack for svMisc to pass R CMD check on these versions
+		if (!exists("index.search", mode= "function")) {
+			index.search <- function (...) return("")
+		}
 		paths <- sapply(.find.package(package, lib.loc, verbose = FALSE),
 			function(p) index.search(fun[i], p, "AnIndex", type = "help"))
 		# Topic is the entry that contains the description
@@ -52,82 +59,87 @@
 	character(length(completions))
 
 #' is this R >= 2.10.0
-R_2_10_0 <- function( ){
+".R_2_10_0" <-
+function ()
+{
 	v <- R.Version()
-	major <- as.numeric( v$major )
-	minor <- as.numeric( v$minor )
-	major > 2 || ( major == 2 && minor >= 10.0 )
+	major <- as.numeric(v$major)
+	minor <- as.numeric(v$minor)
+	return(major > 2 || (major == 2 && minor >= 10.0))
 }
 
-#' version of descArgs for R >= 2.10.0 and its new help system
-#' ultimately the original version should be deleted
-"descArgs_R_2_10_0" <- function (fun, args = NULL, package = NULL, lib.loc = NULL){
-	if( !R_2_10_0() ) stop("cannot use this implementation, needs R >= 2.10.0")
+# Version of descArgs for R >= 2.10.0 and its new help system
+# Ultimately the original version should be deleted
+".descArgs_R_2_10_0" <-
+function (fun, args = NULL, package = NULL, lib.loc = NULL)
+{
+	if (!.R_2_10_0()) stop("cannot use this implementation, needs R >= 2.10.0")
 	
-	# we cannot just call help normally because otherwise it thinks
+	# We cannot just call help normally because otherwise it thinks
 	# we are looking for package "package" so we create a call and eval it
-	help.call <- call( "help", fun, lib.loc = lib.loc, help_type = "text" )
-	if( !is.null(package) ) help.call[["package"]] <- package
-	file <- eval( help.call )
+	help.call <- call("help", fun, lib.loc = lib.loc, help_type = "text")
+	if (!is.null(package)) help.call[["package"]] <- package
+	file <- eval(help.call)
 	
-	# this is borrowed from utils::print.help_files_with_topic
+	# This is borrowed from utils::print.help_files_with_topic
 	path <- dirname(file)
     dirpath <- dirname(path)
     pkgname <- basename(dirpath)
     RdDB <- file.path(path, pkgname)
     
-    if(!file.exists(paste(RdDB, "rdx", sep="."))){
-    	return( character( length(args) ) )
+    if (!file.exists(paste(RdDB, "rdx", sep="."))) {
+    	return(character(length(args)))
     }
     
     rd <- tools:::fetchRdDB(RdDB, basename(file))
     
-    # this is not exported from tools
-    RdTags <- function(Rd) {
+    # This is not exported from tools
+    RdTags <- function (Rd) {
     	res <- sapply(Rd, attr, "Rd_tag")
     	if (!length(res)) res <- character(0)
     	res
     }
-    tags <- gsub( "\\", "", RdTags( rd ), fixed = TRUE ) 
+    tags <- gsub("\\", "", RdTags(rd), fixed = TRUE) 
     
-    if( ! any( tags == "arguments" ) ) return( character(length(args)) )
+    if (!any(tags == "arguments")) return(character(length(args)))
     
-    arguments <- rd[[ which( tags == "arguments" )[1] ]]
-    items <- arguments[ RdTags( arguments ) == "\\item" ]
-    descriptions <- do.call( rbind, lapply( items, function(item){
-    	names <- strsplit( item[[1]][[1]] , "\\s*,\\s*", perl = TRUE )[[1]]
-    	content <- paste( rapply( item[-1] , as.character), collapse = "" )
-    	
-    	cbind( names, rep.int(content, length(names) ) )
-    } ) )
+    arguments <- rd[[which(tags == "arguments")[1]]]
+    items <- arguments[RdTags(arguments) == "\\item"]
+    descriptions <- do.call(rbind, lapply(items, function (item) {
+    	names <- strsplit(item[[1]][[1]], "\\s*,\\s*", perl = TRUE)[[1]]
+    	content <- paste(rapply(item[-1], as.character), collapse = "")
+    	cbind(names, rep.int(content, length(names)))
+    }))
     
-    if( is.null( args ) ){
-    	structure( descriptions[,2], names = descriptions[,1] )
+    if (is.null(args)) {
+    	structure(descriptions[, 2], names = descriptions[, 1])
     } else {
-    	sapply( args, function(a){
-    		if( a %in% descriptions[,1] ){
-    			descriptions[ which(descriptions[,1] == a)[1] , 2 ]
+    	sapply(args, function (a) {
+    		if (a %in% descriptions[, 1]) {
+    			descriptions[which(descriptions[, 1] == a)[1] , 2]
     		} else ""
-    	} )
+    	})
     }
-    
 }
 
-"descArgs" <- function (fun, args = NULL, package = NULL, lib.loc = NULL){
-	
-	# use the new help system if this is R >= 2.10.0
-	if( R_2_10_0() ){
-		return( descArgs_R_2_10_0( fun, args = args, package = package, lib.loc = lib.loc ) )
+"descArgs" <-
+function (fun, args = NULL, package = NULL, lib.loc = NULL)
+{
+	# Use the new help system if this is R >= 2.10.0
+	if (.R_2_10_0()) {
+		return(.descArgs_R_2_10_0(fun = fun, args = args, package = package,
+			lib.loc = lib.loc))
 	}
+	# Otherwise, use the old version (that depends on text rendered help files)
 	
-	# otherwise, use the old version (that depends on text rendered help files)
-	
 	# Start from the text version of the online help instead of the .Rd file
+	# The next line is to avoid raising warnings in R CMD check in R >= 2.10
+	hlp <- function (...) help(...)
 	if (is.null(package)) {
-		File <- as.character(help(fun,
+		File <- as.character(hlp(fun,
 			lib.loc = lib.loc, chmhelp = FALSE, htmlhelp = FALSE))
 	} else {
-		File <- as.character(help(fun, package = parse(text = package),
+		File <- as.character(hlp(fun, package = parse(text = package),
 			lib.loc = lib.loc, chmhelp = FALSE, htmlhelp = FALSE))
 	}
 	if (length(File) == 0) return(character(length(args)))

Modified: pkg/svMisc/R/isHelp.R
===================================================================
--- pkg/svMisc/R/isHelp.R	2009-10-26 06:16:13 UTC (rev 214)
+++ pkg/svMisc/R/isHelp.R	2009-10-26 07:01:29 UTC (rev 215)
@@ -6,8 +6,16 @@
     if (!is.character(topic))
         topic <- deparse(topic)[1]
     INDICES <- .find.package(package, lib.loc, verbose = FALSE)
-    file <- index.search(topic, INDICES, "AnIndex", "R-ex")
-    # Neither help, nor example
+    # index.search() will not be visible any more and will have different
+	# arguments in R 2.11... and it is DEPRECATED in R 2.10
+	# => need to use a different code here!!!
+	# This is a temporary hack for svMisc to pass R CMD check on these versions
+	if (exists("index.search", mode= "function")) {
+		file <- index.search(topic, INDICES, "AnIndex", "R-ex")
+	} else {
+		file <- ""
+	}
+	# Neither help, nor example
 	if (file == "") return(c(help = FALSE, example = FALSE))
     packagePath <- dirname(dirname(file))
     if (length(file) > 1) {



More information about the Sciviews-commits mailing list