[R] Request for help about running a loop and reading .NC files
bgunter@4567 @end|ng |rom gm@||@com
Tue Mar 24 14:49:57 CET 2020
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Mar 24, 2020 at 5:13 AM Bhaskar Mitra <bhaskar.kolkata using gmail.com> wrote:
> Hello Everyone,
> I have written a loop which reads hundreds of .nc files
> and extract information from each .nc file and
> exports that corresponding information as a csv file.
> The loop works fine until it encounters a .nc file which it cannot read
> and the loop stops.
> I would appreciate if anyone can suggest how can I modify
> the loop, whereby the loop will continue to run by bypassing those
> files which it cannot read or if any particular file has an error.
> In the end, I was also hoping to modify the loop such that it
> will generate a report which will inform me which
> files were not read by the loop. The codes are given below
> Thanks for your help,
> Bhaskar Mitra
> setwd("directory path")
> Output <- "directory path"
> flist <- list.files(path ="NCFiles/", pattern = "^.*\\.(nc|NC|Nc|Nc)$")
> for (i in 1: length(flist))
> nc <- nc_open(paste0("NCFiles/",flist[i]))
> mean1 <- ncvar_get(nc,attributes(nc$dim)$names)
> mean_chl_df <- melt(mean1)
> trial.table.df <-as.data.frame(mean_chl_df)
> [[alternative HTML version deleted]]
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help