Skip to content

Commit

Permalink
Fixed issue with dimnames in readNcdf()
Browse files Browse the repository at this point in the history
  • Loading branch information
minoli-pik committed Aug 10, 2022
1 parent ef66ac0 commit 22573d6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions cropCalendars/R/readNcdf.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ readNcdf <- function(file_name = NULL,
warning("Reading a subset of data.")

# Get dimensions subset
idim_list <- list()
idim_list <- dim_list_sub <- list()
# Loop through the dimensions
for (i in seq_len(length(dims))) {
# Which indices should be extracted for dims[i]?
Expand All @@ -83,16 +83,16 @@ readNcdf <- function(file_name = NULL,
# if dims[i] is not specified in dim_subset, read it entirely
idim_list[[dname]] <- seq_len(length(dim_list[[dname]]))
}
dim_list_sub[[dname]] <- dim_list[[dname]][idim_list[[dname]]]
}

# Define start and count for ncvar_get
st <- unlist(lapply(idim_list, min))
ct <- unlist(lapply(idim_list, max)) - st + 1

# Read data from ncdf and assign dimnames to array
nc <- ncvar_get(nf, var_name, start = st, count = ct)
dim(nc) <- unname(ct)
dimnames(nc) <- dim_subset
dimnames(nc) <- dim_list_sub
}

return(nc)
}

0 comments on commit 22573d6

Please sign in to comment.