[rkward-cvs] SF.net SVN: rkward-code:[4567] trunk/rkward/packages/XiMpLe

m-eik at users.sf.net m-eik at users.sf.net
Tue Mar 5 15:14:32 UTC 2013


Revision: 4567
          http://sourceforge.net/p/rkward/code/4567
Author:   m-eik
Date:     2013-03-05 15:14:31 +0000 (Tue, 05 Mar 2013)
Log Message:
-----------
XiMpLe: globally replaced paste(..., sep="") with paste0(...)

Modified Paths:
--------------
    trunk/rkward/packages/XiMpLe/ChangeLog
    trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
    trunk/rkward/packages/XiMpLe/R/node.R
    trunk/rkward/packages/XiMpLe/R/pasteXML-methods.R
    trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R

Modified: trunk/rkward/packages/XiMpLe/ChangeLog
===================================================================
--- trunk/rkward/packages/XiMpLe/ChangeLog	2013-02-28 12:25:30 UTC (rev 4566)
+++ trunk/rkward/packages/XiMpLe/ChangeLog	2013-03-05 15:14:31 UTC (rev 4567)
@@ -1,12 +1,15 @@
 ChangeLog for package XiMpLe
 
-changes in version 0.03-20 (2013-02-26)
+changes in version 0.03-20 (2013-03-05)
 changed:
   - CURRENTLY TURNED OFF: while parsing attributes, XiMpLe will try to force empty attributes into
     attribute="attribute". firstly, empty attributes are not valid XML.
     secondly, they break parsing, because they can't be represented in a list. only
     works if the attribute in question is the last in line. needs improvement
     and should be made optional.
+  - internally replaced paste(..., sep="") calls with paste0(...). for R versions older than
+    2.15 (when paste0() was introduced), a wrapper function should kick in, so we don't need
+    to change the dependencies.
 
 changes in version 0.03-19 (2013-02-24)
 added:

Modified: trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R	2013-02-28 12:25:30 UTC (rev 4566)
+++ trunk/rkward/packages/XiMpLe/R/XiMpLe-internal.R	2013-03-05 15:14:31 UTC (rev 4567)
@@ -1,5 +1,15 @@
 ## internal functions, not exported
 
+## wrapper for paste0() needed?
+if(isTRUE(R_system_version(getRversion()) < 2.15)){
+	# if this is an older R version, we need a wrapper function for paste0()
+	# which was introduced with R 2.15 as a more efficient shortcut to paste(..., sep="")
+	paste0 <- function(..., collapse=NULL){
+		return(paste(..., sep="", collapse=collapse))
+	}
+} else {}
+
+
 ## function child.list()
 # convenience function to let single children be provided without list()
 child.list <- function(children){
@@ -122,9 +132,9 @@
 	indentDiff <- currentMinIndent - level
 	# if currentMinIndent is greater than level, reduce indentation
 	if(indentDiff > 0){
-		tag <- gsub(paste("(^|\n)(\t){", indentDiff, "}", sep=""), "\\1", tag, perl=TRUE)
+		tag <- gsub(paste0("(^|\n)(\t){", indentDiff, "}"), "\\1", tag, perl=TRUE)
 	} else if(indentDiff < 0){
-		tag <- gsub("(^|\n)(\t)", paste("\\1", indent(level + 1, by=indent.by), sep=""), tag, perl=TRUE)
+		tag <- gsub("(^|\n)(\t)", paste0("\\1", indent(level + 1, by=indent.by)), tag, perl=TRUE)
 	} else {}
 
 	return(tag)
@@ -190,7 +200,7 @@
 				} else {
 					attr.name <- this.attr
 				}
-				full.attr <- trim(paste(full.attr, new.attr, new.indent, attr.name, "=\"", attr[[this.attr]], "\"", sep=""))
+				full.attr <- trim(paste0(full.attr, new.attr, new.indent, attr.name, "=\"", attr[[this.attr]], "\""))
 			} else {}
 		}
 	} else {
@@ -201,7 +211,7 @@
 			attr.name <- names(attr)
 		}
 		# look up attribute name to paste
-		full.attr <- paste(attr.name, "=\"", attr[[1]], "\"", sep="")
+		full.attr <- paste0(attr.name, "=\"", attr[[1]], "\"")
 	}
 	return(full.attr)
 } ## end function pasteXMLAttr()
@@ -214,9 +224,9 @@
 			"doctype=\"\\2\", decl=\"\\3\"", tag)
 		stripped.tag2 <- eval(parse(text=paste("c(",gsub("[^\"]*[\"]?([^\"]*)[\"]?[^\"]*", "\"\\1\",", tag),"NULL)")))
 		is.dtd <- grepl("\\.dtd", stripped.tag2)
-		doct.decl <- ifelse(sum(!is.dtd) > 0, paste(stripped.tag2[!is.dtd][1], sep=""), paste("", sep=""))
-		doct.ref <- ifelse(sum(is.dtd) > 0, paste(stripped.tag2[is.dtd][1], sep=""), paste("", sep=""))
-		parsed.list <- eval(parse(text=paste("list(", stripped.tag, ", id=\"", doct.decl,"\"", ", refer=\"", doct.ref,"\")", sep="")))
+		doct.decl <- ifelse(sum(!is.dtd) > 0, paste0(stripped.tag2[!is.dtd][1]), paste0(""))
+		doct.ref <- ifelse(sum(is.dtd) > 0, paste0(stripped.tag2[is.dtd][1]), paste0(""))
+		parsed.list <- eval(parse(text=paste0("list(", stripped.tag, ", id=\"", doct.decl,"\"", ", refer=\"", doct.ref,"\")")))
 	} else if(XML.endTag(tag) | XML.comment(tag) |XML.cdata(tag)){
 		# end tags, comments and CDATA don't have attributes
 		parsed.list <- ""
@@ -449,7 +459,7 @@
 		this.tag <- get("single.tags", envir=single.tags.env)[tag.no]
 		nxt.child <- length(children) + 1
 		child.name <- XML.tagName(this.tag)
-		child.end.tag <- paste("</[[:space:]]*", end.here,"[[:space:]>]+.*", sep="")
+		child.end.tag <- paste0("</[[:space:]]*", end.here,"[[:space:]>]+.*")
 		if(isTRUE(grepl(child.end.tag, this.tag))){
 		## uncomment to debug:
 		# cat(this.tag, ": break (",tag.no,")\n")

Modified: trunk/rkward/packages/XiMpLe/R/node.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/node.R	2013-02-28 12:25:30 UTC (rev 4566)
+++ trunk/rkward/packages/XiMpLe/R/node.R	2013-03-05 15:14:31 UTC (rev 4567)
@@ -49,7 +49,7 @@
 			got.this <- identical(slot(obj, "name"), node[[1]])
 			if(!isTRUE(got.this)){
 				# apparently, this node doesn't exist
-				stop(simpleError(paste("Can't find node ", node[[1]], " in ", sQuote(deparse(substitute(obj))), "!", sep="")))
+				stop(simpleError(paste0("Can't find node ", node[[1]], " in ", sQuote(deparse(substitute(obj))), "!")))
 			} else {
 				# remove first element in list node
 				node[[1]] <- NULL
@@ -62,9 +62,9 @@
 				got.this <- lapply(slot(this.node.part, "children"), function(this.child){slot(this.child, "name")}) %in% this.node
 				if(!any(got.this)){
 					# apparently, this node doesn't exist
-					stop(simpleError(paste("Can't find node ", sQuote(this.node), " in ", sQuote(deparse(substitute(obj))), "!", sep="")))
+					stop(simpleError(paste0("Can't find node ", sQuote(this.node), " in ", sQuote(deparse(substitute(obj))), "!")))
 				} else {
-					result.node.path <- unique(paste(result.node.path, paste("@children[[",which(got.this),"]]", sep=""), sep=""))
+					result.node.path <- unique(paste0(result.node.path, paste0("@children[[",which(got.this),"]]")))
 				}
 			}
 		}
@@ -111,7 +111,7 @@
 		if(!is.null(what)){
 			stopifnot(length(what) == 1)
 			if(!what %in% c(slotNames(new("XiMpLe.node")), "@path", "obj at path")){
-				stop(simpleError(paste("Invalid slot for class XiMpLe.node:", paste(sQuote(what), collapse=", "), "!", sep="")))
+				stop(simpleError(paste0("Invalid slot for class XiMpLe.node:", paste(sQuote(what), collapse=", "), "!")))
 			} else {}
 			if(identical(what, "@path")){
 				## return subtituted path info
@@ -182,7 +182,7 @@
 			# special case: text values can either be directly in the value slot of a node,
 			# or in a pseudo tag as a child node, so we check both and remove all
 			if(identical(what, "value")){
-				eval(parse(text=paste(this.node, "@value <- character()", sep="")))
+				eval(parse(text=paste0(this.node, "@value <- character()")))
 				all.node.children <- slot(eval(parse(text=this.node)), "children")
 				child.is.value <- sapply(all.node.children, function(this.child){
 						if(identical(slot(this.child, "name"), "") & isTRUE(nchar(slot(this.child, "value")) > 0)){
@@ -195,27 +195,26 @@
 				if(length(all.node.children) != length(child.is.value)){
 					warning("a child node contained text values and other nodes, we probably messed up the markup!")
 				} else {}
-				remove.nodes <- paste(this.node, "@children[child.is.value] <- NULL", sep="")
+				remove.nodes <- paste0(this.node, "@children[child.is.value] <- NULL")
 				eval(parse(text=remove.nodes))
 
 				# paste new value into a single pseudo node
-				pseudo.node <- paste(this.node, "@children <- append(", this.node, "@children, ",
-					"new(\"XiMpLe.node\", name=\"\", value=\"", value, "\"), after=0)",
-					sep="")
+				pseudo.node <- paste0(this.node, "@children <- append(", this.node, "@children, ",
+					"new(\"XiMpLe.node\", name=\"\", value=\"", value, "\"), after=0)")
 				eval(parse(text=pseudo.node))
 
 				# now return the object
 				return(obj)
 			} else {
-				this.node <- paste(this.node, "@", what, sep="")
+				this.node <- paste0(this.node, "@", what)
 			}
 
 			if(!is.null(element)){
-				this.node <- paste(this.node, "[[\"",element,"\"]]", sep="")
+				this.node <- paste0(this.node, "[[\"",element,"\"]]")
 			} else {}
 		} else {}
 
-		eval(parse(text=paste(this.node, " <- ", deparse(value), sep="")))
+		eval(parse(text=paste0(this.node, " <- ", deparse(value))))
 	}
 	
 		return(obj)

Modified: trunk/rkward/packages/XiMpLe/R/pasteXML-methods.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXML-methods.R	2013-02-28 12:25:30 UTC (rev 4566)
+++ trunk/rkward/packages/XiMpLe/R/pasteXML-methods.R	2013-03-05 15:14:31 UTC (rev 4567)
@@ -54,13 +54,13 @@
 		} else {}
 
 		if(length(node.chld) > 0){
-			node.chld <- paste(unlist(sapply(node.chld, function(this.node){
+			node.chld <- paste0(unlist(sapply(node.chld, function(this.node){
 				if(slot(this.node, "name") == ""){
-					this.node.pasted <- paste(new.indent, pasteXML(this.node, level=level, shine=shine, indent.by=indent.by, tidy=tidy), sep="")
+					this.node.pasted <- paste0(new.indent, pasteXML(this.node, level=level, shine=shine, indent.by=indent.by, tidy=tidy))
 				} else {
 					this.node.pasted <- pasteXML(this.node, level=(level + 1), shine=shine, indent.by=indent.by, tidy=tidy)
 				}
-				return(this.node.pasted)})), collapse="", sep="")
+				return(this.node.pasted)})), collapse="")
 			node.empty <- FALSE
 		} else {
 			node.chld <- NULL
@@ -74,7 +74,7 @@
 				if(isTRUE(tidy)){
 					node.val <- sapply(node.val, xml.tidy)
 				} else {}
-				node.chld <- paste(node.chld, paste(node.val, new.node, collapse=" "), sep="")
+				node.chld <- paste0(node.chld, paste(node.val, new.node, collapse=" "))
 			} else {}
 		} else {}
 
@@ -110,23 +110,23 @@
 			for (elmt in c("id", "refer")){
 				if(length(tree.doctype[[elmt]]) > 0) {
 					if(nchar(tree.doctype[[elmt]]) > 0){
-						doc.doctype <- paste(doc.doctype, " \"",tree.doctype[[elmt]], "\"", sep="")
+						doc.doctype <- paste0(doc.doctype, " \"",tree.doctype[[elmt]], "\"")
 					} else {}
 				} else {}
 			}
-			doc.doctype <- paste(doc.doctype, ">", new.node, sep="")
+			doc.doctype <- paste0(doc.doctype, ">", new.node)
 		} else {
 			doc.doctype <- ""
 		}
 
 		if(length(tree.nodes) > 0) {
-			doc.nodes <- paste(unlist(sapply(tree.nodes, function(this.node){
-				return(pasteXML(this.node, level=1, shine=shine, indent.by=indent.by, tidy=tidy))})), collapse="", sep="")
+			doc.nodes <- paste0(unlist(sapply(tree.nodes, function(this.node){
+				return(pasteXML(this.node, level=1, shine=shine, indent.by=indent.by, tidy=tidy))})), collapse="")
 		} else {
 			doc.nodes <- ""
 		}
 
-		doc.all <- paste(doc.xml, doc.doctype, doc.nodes, collapse="", sep="")
+		doc.all <- paste0(doc.xml, doc.doctype, doc.nodes, collapse="")
 
 		return(doc.all)
 	}

Modified: trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R
===================================================================
--- trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R	2013-02-28 12:25:30 UTC (rev 4566)
+++ trunk/rkward/packages/XiMpLe/R/pasteXMLTag.R	2013-03-05 15:14:31 UTC (rev 4567)
@@ -61,7 +61,7 @@
 			child <- trim(child)
 			child <- gsub("\n", new.cmmt, setMinIndent(child, level=level, indent.by=indent.by, shine=shine))
 		}
-		full.tag <- paste(child, " ", sep="")
+		full.tag <- paste0(child, " ")
 	} else {
 	switch(tag,
 		"!--"={
@@ -72,9 +72,9 @@
 					child <- gsub("\n", new.cmmt, setMinIndent(child, level=level, indent.by=indent.by, shine=shine))
 				}
 			} else {}
-			full.tag <- paste(new.indent, "<!-- ", new.attr, new.cmmt.indent,
+			full.tag <- paste0(new.indent, "<!-- ", new.attr, new.cmmt.indent,
 				child, " ", new.attr, new.attr.indent,
-				"-->", new.node, sep="")},
+				"-->", new.node)},
 		"![CDATA["={
 			# clean up value if needed
 			if(!is.null(child)){
@@ -83,9 +83,9 @@
 					child <- gsub("\n", new.cmmt, setMinIndent(child, level=level, indent.by=indent.by))
 				}
 			} else {}
-			full.tag <- paste(new.indent, "<![CDATA[ ", new.cmmt, comment.indent,
+			full.tag <- paste0(new.indent, "<![CDATA[ ", new.cmmt, comment.indent,
 				child, " ", new.cmmt, new.indent,
-				"]]>", new.node, sep="")},
+				"]]>", new.node)},
 		"*![CDATA["={
 			# clean up value if needed
 			if(!is.null(child)){
@@ -95,9 +95,9 @@
 				}
 			} else {}
 			# 
-			full.tag <- paste(new.indent, "/* <![CDATA[ */ ", new.cmmt, comment.indent,
+			full.tag <- paste0(new.indent, "/* <![CDATA[ */ ", new.cmmt, comment.indent,
 				child, " ", new.cmmt, new.indent,
-				"/* ]]> */", new.node, sep="")},
+				"/* ]]> */", new.node)},
 		# last but not least, the default value
 		{
 			# only put attributes in new lines if there's more than one
@@ -107,12 +107,12 @@
 			val.indent <- ifelse(shine > 0, indent(level + 1, by=indent.by), "")
 			# empty decides whether this is a empty tag or a pair of start and end tags
 			if(isTRUE(empty)){
-				full.tag <- paste(new.indent, "<", tag, attr.space, new.attr, new.cmmt.indent, all.attributes, new.attr, new.attr.indent, " />", new.node, sep="")
+				full.tag <- paste0(new.indent, "<", tag, attr.space, new.attr, new.cmmt.indent, all.attributes, new.attr, new.attr.indent, " />", new.node)
 			} else {
-				full.tag <- paste(
+				full.tag <- paste0(
 					new.indent, "<", tag, attr.space, new.attr, new.cmmt.indent, all.attributes, new.attr, new.attr.indent, ">", new.node,
-					if(!is.null(child)){paste(val.indent, trim(child), new.node, sep="")},
-					new.indent, "</", tag, ">", new.node, sep="")
+					if(!is.null(child)){paste0(val.indent, trim(child), new.node)},
+					new.indent, "</", tag, ">", new.node)
 			}
 		})
 	}





More information about the rkward-tracker mailing list