cut_system: Use system 'cut' (*NIX only)

Description Usage Arguments Value Author(s) See Also Examples

Description

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

Usage

1
cut_system(cols, filename, sep = "|")

Arguments

cols

integer vector index of columns to cut

filename

character file name

sep

character delimiter (passed to cut)

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
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)
   cut_system(1, filename, sep=",")
   cut_system(4, filename, sep=",")
   cut_system(c(1,4), filename, sep=",")
   unlink(filename)

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