Dear Rees Morrison,


Re:

(...)
> 
> What additional code would create a table output, with the function name in the left column, sorted alphabetically within a pattern, and the pattern of the function in the column to the right.  Users could then sort by those patterns, rename some to suit themselves, etc.
(...)


The version below creates a tab-delimited table with 3 columns: seach string, package name and function name. 
Can be imported e.g. in Excel. Maybe not elegant, but seems to work (however: test it!).
Column order can be changed by changing the printing order of newhits[ ,1]  ,2 and ,3.

In addition, Liviu Andronic's suggestion to use the package "sos" (strange name, but good tip) seems also interesting.

Best wishes,


Franklin Bretschneider
--
Dept of Biology
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands

- - - - - - - - - - - - - - - - - 

#  categorize functions 2.R
#  Franklin Bretschneider
#  after R-help, R. Michael Weylandt
#  08-04-2013
#  this version produces a tab-delimited text file with 
#  the columns: (search) pattern; (in which) package and function (name).
#  ======================================================================
allfuncs = unlist(sapply(search(), ls)) 
n = length(allfuncs)
allnames = names(allfuncs)
package.names = substr(allnames, start=9, stop=nchar(allnames))
allfuncs = cbind(package.names, allfuncs)
#  which patterns to search: can be customized
patterns = c("print", "plot", "axes", "axis", "color", "file", "read", "write", "load", "save","wave", "image", "table", "data", "apply", "title", "matrix", "names")
patterns = sort(patterns)  #  optional
k = length(patterns)
#  open output file
options(verbose=FALSE)
zz <- file("all functions.txt", open="wt")
sink(zz, type="output")
#  print the output to the file
cat("\n\n ")
cat("pattern\tpackage\tfunction\r")
for (i in 1:k) {
	cat("\n ")
	hits = allfuncs[grep(patterns[i], allfuncs[,2], ignore.case=TRUE),2]
	hitpkg = allfuncs[grep(patterns[i], allfuncs[,2], ignore.case=TRUE),1]
	hitpkg = gsub("\\d", "", hitpkg)
	labels = rep(patterns[i],length(hits))
	newhits = cbind(labels, hitpkg, hits)
		newhits =newhits[order(newhits[,3]),]  # sort data frame on basis of one column
	cat(sprintf(fmt = "%s\t%s\t %s\r", newhits[,1], newhits[,2], newhits[,3]))
	}
cat("\n\n")
## back to the console
sink(type="output")
close(zz)  #  close the file
print("Finished")





	[[alternative HTML version deleted]]

