I am trying to use furrr for a parallel processing. I have a netcdf with about 700000 files in it, with an ID of 1-700000. The file is a time series and don't have lat and lon. For each file, I am trying to compute some stat and save all in to one csv. Here is the code, I modified (thanks @MyKo101)
file <- nc_open("Merged.nc")
ID <- ncvar_get(file, "ID")
run_file <- function(file) {
for (i in 1:length(ID)) {
tryCatch({
prcp <- ncvar_get(file, varid = "prcp", start = c(i, 1), count = c(1, -1))
dur <- ts(prcp, start=1979)
mk = mk.test(dur)
sample_filename <- ID[i]
res <- data.frame(sample_filename = sample_filename ,mk$p.value)
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}}
plan(multiprocess)
dt <- future_map_dfr(file,run_file, .progress=TRUE)
write.csv(dt,"test_par.csv")
ERROR : first argument (nc) is not of class ncdf4!
Can you help with the code?