grep_system: Use system 'grep' (*NIX only)

Description Usage Arguments Value Author(s) See Also Examples

Description

Use system grep (*NIX only). For large files this is much faster than reading the file into R and grepping the columns.

Usage

1
grep_system(pattern, filename, options = "")

Arguments

pattern

character to search

filename

character file name

options

character passed to grep

Value

character vector output from cut

Author(s)

Thomas P. Harte

See Also

system, cut

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
tab<- read.csv(text='Name,Age,Salary,ID
            Dick,38,32k,1
            Tom,21,21k,2
            Harry,56,NA,3',
            header=TRUE,
            stringsAsFactors=FALSE
   )
   for (col in which(col_classes(tab)=="character"))
       tab[, col]<- tutils::trim(tab[, col])
   tab

   filename<- paste(tempfile(), ".csv", sep="")
   write.csv(tab, file=filename, row.names=FALSE, quote=FALSE)
   grep_system("Tom", filename)
   grep_system("Dick", filename)
   grep_system("harry", filename, options="-i")

   unlink(filename)

tharte/tutils documentation built on Feb. 11, 2020, 9:17 a.m.