2

I'm wondering if there is a way to get readr::read_tsv to read block gzip files with .bgz extension. I could rename the files to have .gz (which read_tsv automatically recognizes) which does work, but I don't want to do that everytime I get new files.

Thanks!

Jon Chung
  • 145
  • 5

2 Answers2

3

You can pass a connection object rather than a file path. For example

read_tsv(gzfile("data.bgz"))

The gzfile() function will take any file name.

MrFlick
  • 195,160
  • 17
  • 277
  • 295
0

You can rename the file if it is a bgz via R:

library(fs)
library(stringr)
library(readr)
# Regular expression to find your dataset file named datasetname
# You'll need to change that to the actual name
tsv_file <- dir_ls(".", regexp = "datasetname.*\\.b?gz")
if (str_detect(tsv_file, "bgz"))
    file_move(tsv_file, str_replace(tsv_file, "bgz$", "gz"))
dataset <- read_tsv(tsv_file)
Luke W. Johnston
  • 954
  • 9
  • 17
  • Thanks for the help. I did try something similar by renaming files using `mv` in shell. But these files can be relatively large and shared with other users, so I would like to avoid renaming them. – Jon Chung Mar 18 '19 at 14:14