Reading NetCDF file within tar.gz file without extracting the tar file

tarfile <- "C:/Users/admin/Desktop/ty/7_netcdf_files/2000.tar" #reading in the file of interest ( year 2000)

untar(tarfile = "2000.tar", exdir = "./rain_files") #extracting the netCDF files from the tar and saving to a new directory that I named rain_files

Hi all,
I have 6 month's worth of precipitation data being collected every 15 mins for the years 2000-2021. I am trying to analyze the files in R and was wondering if there was a way to do this without extracting each of the .tar files one by one. I used the untar function like above to do this for a few years but it took a long time!! I am most interested in the netCDF files that are housed within the tar files. Is there a way to read this information without extracting each tar file?

To selectively pull files from an archive, there’s an option in utils::untar() See here. If looking to selectively choose archives instead of files, do a list of files to include or exclude and write a function for a loop or sapply.

Thank you so much!! I was having a hard time with this and kept finding resources for other programming programs but not for R! I am going to check out the resource you linked.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.