getWikiRcode <- function(wikipage, url = "http://wiki.r-project.org/rwiki",
	strip.empty.lines = TRUE, strip.output = FALSE) {
	# Read the raw wiki page
	Url <- paste(url, "/doku.php?id=", wikipage, "&do=export_raw", sep ="")
	Raw <- readLines(Url)
	
	# Get only <code r> .... </code> chunks from this page
	Codestart <- grep("^\\s*<code", Raw)
	Codeend <- grep("^\\s*</code>", Raw)
	# A little bit of checking first
	if (length(Codestart) != length(Codeend) || any(Codeend <= Codestart))
		stop("Malformed wiki page (wrong <code>... </code> sections)")	
	# Get only r code sections (those starting with <code r> from the list
	Rstart <- grep("^\\s*<code r>", Raw)
	if (length(Rstart) == 0) return(character(0))	# no R code in this page
	isRsection <- Codestart %in% Rstart
	Rend <- Codeend[isRsection]
	
	# Construct the list of text lines related to r code
	R <- data.frame(Start = Rstart, End = Rend)
	Seq <- function(x) seq(from = x[1], to = x[2])
	Rrows <- c(apply(R, 1, Seq), recursive = TRUE)
	Rcode <- Raw[Rrows]
	
	# Eliminate <code r> and </code> tags
	Rcode <- gsub("^\\s*</?code( r)?>.*$", "", Rcode)
	
	# Eliminate prompt from R code '> ', or '+ ' at the begining of a line
	Rcode <- sub("^[>+] ", "", Rcode)
	
	# Possibly eliminate empty lines
	if (strip.empty.lines) Rcode <- Rcode[Rcode != ""]
	
	# Possibly eliminate output (lines starting with '#!')
	if (strip.output) {
		Routput <- grep("^\\#\\!", Rcode)
		if (length(Routput) > 0) Rcode <- Rcode[-Routput]
	}
	
	# Return the R code
	return(Rcode)
}

rcode <- getWikiRcode("tips:data-frames:merge")
rcode

sourceWikiRcode <- function(wikipage, echo = TRUE, url = "http://wiki.r-project.org/rwiki",
	strip.empty.lines = TRUE, strip.output = FALSE, ...) {
	# Call getWikiRcode() to extract r code from wiki pages
	Rcode <- getWikiRcode(wikipage = wikipage, url = url,
		strip.empty.lines = strip.empty.lines, strip.output = strip.output)
	if (length(Rcode) == 0) {
		warning("No r ocde in this page!")
	} else {
		Con <- textConnection(Rcode)
		source(Con, echo = echo, ...)
		close(Con)
	}
}

sourceWikiRcode("tips:data-frames:merge")
# Here, the last part of this page is not directly executable (data1 is not defined)
# but the rest is fine!