[R] demo() function returns alphabetical matches, not unique matches?

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 8 10:44:42 CEST 2003


Actually, demo matches the `topic' as a regular expression, that is 
anywhere in the file basename and with certain characters being special.
So

demo("^logit")

will probably work (it does work for the system demos).

Clearly that is too sopisticated (and not documented).  For the next 
release I will alter this to accept exact matches only.  If you need this 
now, the code in demo is

        ## files with correct extension
        files <- files[sub(".*\\.", "", files) %in% c("R", "r")]
        ## Files with base names matching topic
        basenames <- sub("\\.[Rr]$", "", files)
        files <- files[topic == basenames]

the last two lines replacing

        files <- files[grep(topic, files)]


On Wed, 6 Aug 2003, Olivia Lau wrote:

> Hi, 
> 
> I'm working on a set of demo files for a package, and I'm having a
> problem because I have two demo files (one called "logit", the other
> called "blogit") and when I type demo(logit), it gives me demo(blogit)
> instead.  (And calls it the the demo for logit.)
> 
> I've figured out that this is because the demo() function searches
> through all the demo directories (in the installed libraries) and looks
> for the string "logit" and takes only the first match in alphabetical
> order [?] (which is "blogit" in this case).
> 
> Is there any way to modify the demo() function so that it looks for the
> exact match, not a match for the string?  I could of course rename the
> demo file, but I'm afraid that students won't remember it (blogit is a
> name of a function as well).
> 
> Thanks in advance, 
> 
> Olivia Lau, 
> "Novice R Programmer"  
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list