Is possible to use fwrite from `data.table` with gzfile?

You can use the gzip function in R.utils:

library(R.utils)
library(data.table)

#Write gzip file
df <- data.table(var1='Compress me',var2=', please!')
fwrite(df,'filename.csv',sep=',')
gzip('filename.csv',destname='filename.csv.gz')`

# Read gzip file
fread('gzip -dc filename.csv.gz')
          var1      var2
1: Compress me , please!

UPDATE: As of 2019-10-03 the below change is also released on CRAN (starting with version 1.12.4), so a simple install.packages("data.table") should now suffice.

data.table now supports fwrite() directly to gzipped csvs. As of Aug 28 2019 this is not released on CRAN, but you can get it by installing from GitHub:

# Install development version of data.table
install.packages("data.table", repos="https://Rdatatable.gitlab.io/data.table")

# Generate some data
library(data.table)
dt <- data.table(
  state = sample(state.name, size = 1e6, replace = TRUE),
  measure = runif(1e6)
)

# Write to a gzipped file
data.table::fwrite(dt, file = "dt.gz")

# Read back
library(R.utils)
dt2 <- data.table::fread("dt.gz")