From e14f7441b053c0506d66adb2722763e601304fa3 Mon Sep 17 00:00:00 2001 From: Mengqi Zhao Date: Mon, 8 Jan 2024 18:59:19 -0800 Subject: [PATCH 1/2] update docs.yaml --- .github/workflows/docs.yaml | 5 +++-- R/read_ncdf.R | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index bd1179d..5a85a80 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -2,6 +2,7 @@ on: push: branches: - main + - dev name: docs @@ -11,7 +12,7 @@ jobs: env: GITHUB_PAT: ${{ secrets.PAT }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: r-lib/actions/setup-r@v2 @@ -25,7 +26,7 @@ jobs: shell: Rscript {0} - name: Cache R packages - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ${{ env.R_LIBS_USER }} key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} diff --git a/R/read_ncdf.R b/R/read_ncdf.R index 86a8d9b..9732cf5 100644 --- a/R/read_ncdf.R +++ b/R/read_ncdf.R @@ -28,7 +28,7 @@ read_ncdf <- function(ncdf = NULL, var_names <- attributes(ncdf_in$var)$names # get unit - var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit[1] + var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit dims <- c(ncdf_in$var[[var]]$dim[[1]]$name, ncdf_in$var[[var]]$dim[[2]]$name, @@ -121,7 +121,7 @@ read_ncdf <- function(ncdf = NULL, var_names <- attributes(ncdf_in$var)$names # get unit - var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit[1] + var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit dims <- c(ncdf_in$var[[var]]$dim[[1]]$name, ncdf_in$var[[var]]$dim[[2]]$name, From f5a776c397b2746489218adc45483bdecbb71ca4 Mon Sep 17 00:00:00 2001 From: Mengqi Zhao Date: Tue, 9 Jan 2024 07:54:32 -0800 Subject: [PATCH 2/2] Update read_ncdf.R --- R/read_ncdf.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/R/read_ncdf.R b/R/read_ncdf.R index 9732cf5..379354d 100644 --- a/R/read_ncdf.R +++ b/R/read_ncdf.R @@ -27,9 +27,6 @@ read_ncdf <- function(ncdf = NULL, ncdf_in <- ncdf4::nc_open(ncdf) var_names <- attributes(ncdf_in$var)$names - # get unit - var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit - dims <- c(ncdf_in$var[[var]]$dim[[1]]$name, ncdf_in$var[[var]]$dim[[2]]$name, ncdf_in$var[[var]]$dim[[3]]$name) @@ -39,6 +36,9 @@ read_ncdf <- function(ncdf = NULL, stop('Climate variable name is not valid. Please provide valid ncdf_var name.') } + # get unit + var_unit <- ncdf4::ncatt_get(ncdf_in, var)$unit + # get the data time series ncdf_brick <- raster::brick(ncdf, varname = var, ncdf = TRUE, dims = dims_order, stopIfNotEqualSpaced = F) @@ -120,9 +120,6 @@ read_ncdf <- function(ncdf = NULL, ncdf_in <- ncdf4::nc_open(ncdf) var_names <- attributes(ncdf_in$var)$names - # get unit - var_unit <- ncdf4::ncatt_get(ncdf_in, var_names)$unit - dims <- c(ncdf_in$var[[var]]$dim[[1]]$name, ncdf_in$var[[var]]$dim[[2]]$name, ncdf_in$var[[var]]$dim[[3]]$name) @@ -132,6 +129,9 @@ read_ncdf <- function(ncdf = NULL, stop('Climate variable name is not valid. Please provide valid ncdf_var name.') } + # get unit + var_unit <- ncdf4::ncatt_get(ncdf_in, var)$unit + ncdf_brick <- raster::brick(ncdf, varname = var, ncdf = TRUE, dims = dims_order, stopIfNotEqualSpaced = F)