Olivia Lau
2003-Aug-06 20:10 UTC
[R] demo() function returns alphabetical matches, not unique matches?
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]]
Prof Brian Ripley
2003-Aug-08 08:44 UTC
[R] demo() function returns alphabetical matches, not unique matches?
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