[R] grep() exclude certain patterns?

Peng Yu pengyu.ut at gmail.com
Tue Dec 8 23:38:12 CET 2009


On Fri, Dec 4, 2009 at 6:12 PM, Gavin Simpson <gavin.simpson at ucl.ac.uk> wrote:
> On Fri, 2009-12-04 at 15:18 -0600, Peng Yu wrote:
>> On Fri, Dec 4, 2009 at 3:06 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
>> > On Fri, Dec 4, 2009 at 2:35 PM, Greg Snow <Greg.Snow at imail.org> wrote:
>> >> The invert argument seems a likely candidate, you could also do perl=TRUE and use negations within the pattern (but that is probably overkill for your original question).
> </snip />
>> Here is another bad example. See ?rep. The Usage section has 'rep(x,
>> ...)'. However, '...' is only explained later in Arguments. I know
>> that it is probably because '...' is from functions underlying rep().
>> But it does not matter to end users whether they are from an
>> underlying function or not. Why not put the arguments in the Usage
>> section?
>
> Because '...' is the argument to rep. Should we document very argument
> for every rep method in existence within this help file? The '...' has
> nothing to do with functions underlying rep if you mean "inside" rep, it
> is just the means by which arguments are passed from the generic to
> methods for objects of particular classes.

I knew what '...' means.

Let's take the following example to be clear what I mean. In order to
know what additional arguments can be passed to fun1() besides 'data',
'data.frame', 'graph', 'limit', I need to know fun1() calls par(). But
the information of which functions are called are not well documented
in the help. Then how can a user know the complete set of arguments
that can be passed to fun1()? I would say '...' makes the
implementation of functions easier but make the maintenance difficult.

fun1 <- function(data, data.frame, graph=TRUE, limit=20, ...) {
[omitted statements]
if (graph)
par(pch="*", ...)
[more omissions]
}

C has a similar grammar of '...' to accept any arguments, which was
useful in the old days. But I don't see any working examples in C++
that support '...'. C++ eliminates the usage of '...' by using classes
as arguments. But eliminating '...', the code will be more
understandable. I believe this is possible in R if we want to do so.

>> Similar cases can be found in the help of many functions.
>
> Probably because that's how the S3 method system works.
>
> If you learn how and why the R system works, things will make much more
> sense.
>
> G
>
> <snip />
> --
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>
>




More information about the R-help mailing list