3 comments on “A word of warning about grep, which and the like

  1. use grepl instead.

    e.g.
    colSlice <- function(dat,pattern,…){
    dat[,grepl(pattern,names(dat),...)]
    }

  2. In general (beyond “grep” and “which”) you can avoid this sort of problem by creating new temporary variables rather than overwriting the existing variable. This is a minor pain because you end up with variables dat1, dat2, dat3, … representing the steps of the analysis, but may be worth it in the long run.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s