I would like to use fread to pull in only columns with names that match a condition. (In this case, I would like to pull in all columns that contain the label email.) Imagine that you have this data in a file called tempdata.txt in your working directory:
col1,col2,col3,email1,email2,col4,url1,url2,col5
1,2,3,4,5,6,7,8,9
9,8,7,6,5,4,3,2,1
x,x,x,me@me.com,you@you.com,y,y,y,y
a,a,a,a,a,a,http://google.com,http://stackoverflow.com,a
It is possible to use fread to load a subset of the columns if you know the names:
test <- data.table::fread("tempdata.txt", select=c("email1","email2"))
> test
email1 email2
1: 4 5
2: 6 5
3: me@me.com you@you.com
4: a a
Is it also possible to select using a string match? I am trying to mimic this behavior but within the fread command:
> all <- data.table::fread("tempdata.txt")
> all %>% select(contains("email"))
email1 email2
1: 4 5
2: 6 5
3: me@me.com you@you.com
4: a a
Thanks for any insight.