s-news
[Top] [All Lists]

Re: locate text in function(s)

To: <carr.gj@pg.com>, "'Kamil Toth'" <kamiltoth@yahoo.com>
Subject: Re: locate text in function(s)
From: <Rich@Mango-Solutions.com>
Date: Thu, 8 Dec 2005 09:20:20 -0000
Cc: <s-news@lists.biostat.wustl.edu>
In-reply-to: <OF8A93EC50.AABB9299-ON852570D0.0072FBD2-852570D0.00738D5E@na.pg.com>
Thread-index: AcX7cYiB5Ddt0tBcTp2wg04LoaxaiwAZTOsQ

Thought I'd send a quick apply-based alternative …

> funStr <- function(pattern, funs = objects(class = "function")) {

        lFind <- sapply(funs, function(txt, pattern) length(grep(pattern, as.character(get(txt)))), pattern = pattern)

        funs[lFind > 0]

}

> funStr("sd", objects(2, class = "function"))

 [1] "agnes"                        "anova.censorReg"              "as.trellis.data.frame.series" "as.trellis.data.frame.signal" "biplot.princomp"              "censorReg"                    "censorReg.make.Y"             "clara"                      

 [9] "clusplot.default"             "cov.wt"                       "daisy"                        "data.ed"                      "diana"                        "dmvnorm"                      "fanny"                        "holiday.Australia"          

[17] "holiday.NYSE"                 "holiday.Thanksgiving"         "is.dir"                       "kaplanMeier"                  "kaplanMeier.control"          "kaplanMeier.fit"              "multicomp.default"            "normal.sample.size"         

[25] "pam"                          "pattern"                      "plot.moving.sd"               "plot.multicomp"               "plot.signalSeries"            "plot.timeSeries"              "pmvnorm"                      "predict.princomp"           

[33] "predict.tree"                 "princomp"                     "print.censorReg"              "print.multicomp"              "print.multicomp.discrim"      "print.princomp"               "print.qcc"                    "print.shewhart"             

[41] "print.survreg"                "prompt.d"                     "prompt.data.frame"            "prompt.data.frame.d"          "prompt.default"               "promptHtml"                   "prune.tree"                   "qcc"                        

[49] "qqplot.censorReg.cdpoints"    "rmvnorm"                      "rotate.princomp"              "sablplot"                     "screeplot.princomp"           "sd.R"                         "sd.ewma"                      "sd.mR"                      

[57] "sd.ma"                        "sd.ms"                        "sd.s"                         "sd.xbar"                      "summary.censorReg"            "summary.discrim"              "summary.princomp"             "summary.survReg"            

[65] "summary.survreg"              "survReg.fit"                  "survpenal.fit"                "survreg"                      "survreg.fit"                  "survsum"                      "timeZoneS"                    "window.its"                 

Rich.

S-PLUS and R Training and Consulting

mangosolutions

Tel   +44 118 902 6617

Fax  +44 118 902 6401


________________________________________

From: s-news-owner@lists.biostat.wustl.edu [mailto:s-news-owner@lists.biostat.wustl.edu] On Behalf Of carr.gj@pg.com

Sent: 07 December 2005 21:02

To: Kamil Toth

Cc: s-news@lists.biostat.wustl.edu

Subject: Re: [S] locate text in function(s)


I may be among the "smart people":

functionString<-function(candidates,string){

        ###candidates is character vector (names of objects)

        ###string is text to be matched (regular _expression_)

        results<-logical(length(candidates))

        for (i in seq(along=candidates)){

                if (is.function(get(candidates[i]))){

                        if (any(regexpr(string,deparse(get(candidates[i])))>0)) results[i]<-T

                }

        }

        candidates[results]

}

##example (checks all objects in first pos of search list)

functionString(objects(),string="data\\.frame")



Kamil Toth <kamiltoth@yahoo.com>

Sent by: s-news-owner@lists.biostat.wustl.edu

12/07/2005 02:23 PM        

        To:        "s-news@lists.biostat.wustl.edu" <s-news@lists.biostat.wustl.edu>

        cc:        

        Subject:        [S] locate text in function(s)


Folks:

Suppose that I have several hundred functions in one project, and I need to quickly locate which of them contains a specific text, say "my.SPLINE". Is there any regular way of doing this? If not, what would you, smart people, do to fulfil this task?

Thanks

Kamil Toth

 

________________________________________

Yahoo! Personals

Let fate take it's course directly to your email.

See who's waiting for you Yahoo! Personals

<Prev in Thread] Current Thread [Next in Thread>