[R-gregmisc-users] SF.net SVN: r-gregmisc:[1761] trunk/gtools
Brought to you by:
warnes
From: <wa...@us...> - 2013-12-23 18:48:18
|
Revision: 1761 http://sourceforge.net/p/r-gregmisc/code/1761 Author: warnes Date: 2013-12-23 18:48:15 +0000 (Mon, 23 Dec 2013) Log Message: ----------- Extend the keywords() function to return keywords associated with a specified topic via 'keywords(topic)'. Modified Paths: -------------- trunk/gtools/R/keywords.R trunk/gtools/man/keywords.Rd Modified: trunk/gtools/R/keywords.R =================================================================== --- trunk/gtools/R/keywords.R 2013-12-23 16:08:10 UTC (rev 1760) +++ trunk/gtools/R/keywords.R 2013-12-23 18:48:15 UTC (rev 1761) @@ -1,5 +1,33 @@ -keywords <- function( ... ) +keywords <- function( topic ) { + file <- file.path(R.home("doc"),"KEYWORDS") - file.show(file, ...) + if(missing(topic)) + { + file.show(file) + } + else + { + kw <- scan(file=file, what=character(), sep="\n", quiet=TRUE) + kw <- grep("&", kw, value=TRUE) + kw <- gsub("&[^&]*$","", kw) + kw <- gsub("&+"," ", kw) + kw <- na.omit(trim(kw)) + + ischar <- tryCatch(is.character(topic) && length(topic) == + 1L, error = identity) + if (inherits(ischar, "error")) + ischar <- FALSE + if (!ischar) + topic <- deparse(substitute(topic)) + + item <- paste("^",topic,"$", sep="") + + topics <- function(k) help.search(keyword=k)$matches[,"topic"] + matches <- lapply(kw, topics) + names(matches) <- kw + + tmp <- unlist(lapply( matches, function(m) grep(item, m, value=TRUE) )) + names(tmp) + } } Modified: trunk/gtools/man/keywords.Rd =================================================================== --- trunk/gtools/man/keywords.Rd 2013-12-23 16:08:10 UTC (rev 1760) +++ trunk/gtools/man/keywords.Rd 2013-12-23 18:48:15 UTC (rev 1761) @@ -5,21 +5,24 @@ List valid keywords for R man pages } \usage{ -keywords(...) +keywords(topic) } \arguments{ - \item{\dots}{Optional argumenst to pass to show.file()} + \item{topic}{object or man page topic} } \details{ - This function simply determines the path \$RHOME/doc/KEYWORDS and calls - show.file() to display it. + If \code{topic} is provided, return a list of the keywords associated + with \code{topic}. Otherwise, display the list of valid R keywords + from the R doc/KEYWORDS file. } -\value{ - Nothing of interest. -} \author{Gregory R. Warnes \email{gr...@wa...}} \seealso{ \code{\link[utils]{help}} } \examples{ +## Show all valid R keywords keywords() + +## Show keywords associated with the 'merge' function +keywords(merge) +keywords("merge") } \keyword{documentation} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |