[R] test if elements of a character vector contain letters

R. Michael Weylandt michael.weylandt at gmail.com
Tue Aug 7 20:47:22 CEST 2012


On Tue, Aug 7, 2012 at 4:28 AM, Liviu Andronic <landronimirc at gmail.com> wrote:
> On Mon, Aug 6, 2012 at 7:35 PM, Marc Schwartz <marc_schwartz at me.com> wrote:
>> is.letter <- function(x) grepl("[[:alpha:]]", x)
>> is.number <- function(x) grepl("[[:digit:]]", x)
>>
> Quick follow-up question.
>
> I'm always reluctant to create functions that would resemble the
> method of a function (here, is() ), but would in fact not be a genuine
> method. So would there be any incompatibility between is() and
> is.letter(), given that the latter is not a method of the former?
> Is it good (or acceptable) practice to define is.letter() as above?
> Would is_letter() be better?

It certainly won't cause problems if you never define anything of
class "letter" or "number".

>
> Regards
> Liviu
>



More information about the R-help mailing list