diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index bf69a50e3..8f8501c67 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -24,7 +24,7 @@ jobs: config: - {os: windows-latest, r: 'release', not_cran: false} - {os: macOS-latest, r: 'release', not_cran: false} - - {os: ubuntu-latest, r: 'release', not_cran: true} + - {os: ubuntu-latest, r: 'release', not_cran: true, _EPLUSR_SKIP_TESTS_TRANSITION_: true, _EPLUSR_SKIP_TESTS_DOWNLOAD_EPW_: true, _EPLUSR_SKIP_TESTS_DOWNLOAD_IDD_: true, _EPLUSR_SKIP_TESTS_BASEMENT_: true} env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pkgdown.yml b/.github/workflows/pkgdown.yml index c8be838cf..6b8ba4d9f 100644 --- a/.github/workflows/pkgdown.yml +++ b/.github/workflows/pkgdown.yml @@ -22,7 +22,6 @@ jobs: env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} - NOT_CRAN: true RGL_USE_NULL: true steps: @@ -47,6 +46,6 @@ jobs: Rscript -e 'pkgdown::deploy_to_branch(new_process = FALSE)' - name: Build site without deploying - if: github.event_name == 'pull_request' + if: ${{ github.event_name == 'pull_request' && !contains(github.event.head_commit.message, '[skip-website]') }} run: | Rscript -e 'pkgdown::build_site(preview = FALSE, install = FALSE)' diff --git a/DESCRIPTION b/DESCRIPTION index 46c4954fd..2083947b2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: eplusr Title: A Toolkit for Using Whole Building Simulation Program 'EnergyPlus' -Version: 0.15.2 +Version: 0.15.2.9001 Authors@R: c( person(given = "Hongyuan", family = "Jia", @@ -46,7 +46,7 @@ Suggests: Encoding: UTF-8 Roxygen: list(markdown = TRUE, roclets = c("rd", "namespace", "collate")) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.2 SystemRequirements: EnergyPlus (optional) (); udunits2 Collate: diff --git a/NAMESPACE b/NAMESPACE index 3f3498d37..96b1d1891 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -296,7 +296,6 @@ importFrom(lubridate,force_tz) importFrom(lubridate,hours) importFrom(lubridate,leap_year) importFrom(lubridate,make_date) -importFrom(lubridate,make_datetime) importFrom(lubridate,mday) importFrom(lubridate,minutes) importFrom(lubridate,month) diff --git a/NEWS.md b/NEWS.md index 7d1a51f20..953ae829b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# eplusr (development version) + +## Bug fixes + +* Fix EPW parsing error due to an update of lubridate (#532). + # eplusr 0.15.2 ## New features diff --git a/R/impl-epw.R b/R/impl-epw.R index 3df0da791..b222d1634 100644 --- a/R/impl-epw.R +++ b/R/impl-epw.R @@ -1,7 +1,7 @@ #' @importFrom stringi stri_isempty stri_match_first_regex stri_replace_all_charclass #' @importFrom stringi stri_split_charclass stri_split_fixed stri_sub "stri_sub<-" #' @importFrom stringi stri_trans_tolower stri_trans_totitle stri_trans_toupper -#' @importFrom lubridate as_datetime make_date make_datetime force_tz tz +#' @importFrom lubridate as_datetime make_date force_tz tz #' @importFrom lubridate days_in_month minutes hours days years leap_year #' @importFrom lubridate mday month yday year "year<-" parse_date_time #' @importFrom data.table "%chin%" chmatch copy fread fwrite as.data.table @@ -187,7 +187,7 @@ parse_epw_file <- function (path, idd = NULL, encoding = "unknown") { set(epw_data, NULL, "line", seq_len(nrow(epw_data))) # parse date time - epw_data[, datetime := lubridate::make_datetime(year, month, day, hour, tz = "UTC")] + epw_data[, datetime := stringi::stri_datetime_create(year, month, day, hour, tz = "UTC", lenient = TRUE)] # match date time matched <- match_epw_data(epw_data, epw_header) @@ -2223,10 +2223,11 @@ merge_epw_new_data <- function (epw_data, epw_header, matched, data, target_peri # }}} # check if the datetime is valid - expect_start <- make_datetime( + expect_start <- stringi::stri_datetime_create( lubridate::year(start), lubridate::month(start), lubridate::mday(start), # hour # minute - 0L, step + 0L, step, + tz = "UTC", lenient = TRUE ) if (start != expect_start) { abort(paste0("Invalid starting date time found in input data. ", @@ -2336,7 +2337,7 @@ merge_epw_new_data <- function (epw_data, epw_header, matched, data, target_peri set(data, NULL, "hour", data$hour + 1L) # ignore minute when validation - set(data, NULL, "datetime", lubridate::make_datetime(data$year, data$month, data$day, data$hour, tz = lubridate::tz(data$datetime))) + set(data, NULL, "datetime", stringi::stri_datetime_create(data$year, data$month, data$day, data$hour, tz = lubridate::tz(data$datetime), lenient = TRUE)) } m <- match_epw_data(data, header, target_period) diff --git a/R/impl-sql.R b/R/impl-sql.R index 6b35e75b3..805d12020 100644 --- a/R/impl-sql.R +++ b/R/impl-sql.R @@ -1,6 +1,6 @@ #' @importFrom RSQLite SQLite dbConnect dbDisconnect dbGetQuery dbListTables dbReadTable #' @importFrom data.table setDT setcolorder setorder -#' @importFrom lubridate year force_tz make_datetime +#' @importFrom lubridate year force_tz NULL # RPFREQ {{{ @@ -400,7 +400,8 @@ create_sql_datetime <- function (time, first_day = NULL, year = NULL, tz = "UTC" } set(time, NULL, "datetime", - lubridate::make_datetime(time$year, time$month, time$day, time$hour, time$minute, tz = tz) + # see https://github.com/tidyverse/lubridate/issues/1098 + stringi::stri_datetime_create(time$year, time$month, time$day, time$hour, time$minute, tz = tz, lenient = TRUE) ) set(time, NULL, "year", NULL) diff --git a/tests/testthat/test-assert.R b/tests/testthat/test-assert.R index 00cfc7ec5..71a679077 100644 --- a/tests/testthat/test-assert.R +++ b/tests/testthat/test-assert.R @@ -28,6 +28,7 @@ test_that("Assertion functions", { file.create(file.path(tempdir(), "energyplus.exe")) is_eplus_path(tempdir()) }) + unlink(file.path(tempdir(), c("Energy+.idd", "energyplus", "energyplus.exe"))) expect_false(is_idd(1)) expect_true(is_idd(use_idd(8.8, download = "auto"))) diff --git a/tests/testthat/test-run.R b/tests/testthat/test-run.R index 1dd69f4e6..3a95bc6cf 100644 --- a/tests/testthat/test-run.R +++ b/tests/testthat/test-run.R @@ -187,6 +187,7 @@ test_that("ExpandObjects()", { test_that("Basement()", { skip_on_cran() + skip_if(Sys.getenv("_EPLUSR_SKIP_TESTS_BASEMENT_") != "") out_dir <- file.path(tempdir(), "Basement") if (!dir.exists(out_dir)) dir.create(out_dir) @@ -298,6 +299,7 @@ test_that("Basement()", { test_that("Slab()", { skip_on_cran() + skip_if(Sys.getenv("_EPLUSR_SKIP_TESTS_BASEMENT_") != "") out_dir <- file.path(tempdir(), "Basement") if (!dir.exists(out_dir)) dir.create(out_dir) @@ -603,44 +605,46 @@ test_that("energyplus()", { expect_true(is.na(files["experr"])) unlink(c(path_exp, out_dir), recursive = TRUE) - # can run Basement - path_base <- copy_eplus_example(8.8, "LgOffVAVusingBasement.idf") - expect_error(energyplus(path_base, NULL, out_dir, echo = FALSE)) - # modify the input in order to reduce the simulation time - l <- read_lines(path_base) - l[grepl("IYRS: Maximum number of yearly iterations", string), string := "1;"] - write_lines(l, path_base) - res_base <- energyplus(path_base, weather, out_dir, design_day = TRUE, echo = FALSE) - expect_equal(length(res_base$file), 57L) - expect_equal({files <- unlist(res_base$file); files <- files[!is.na(files)]; length(files)}, 27L) - expect_equal(sum(!file.exists(file.path(out_dir, files))), 0L) - expect_equal(sort(unname(files[names(files) != "epw"])), list.files(out_dir, "LgOffVAVusingBasement")) - expect_equal(res_base$run[program == "Basement", exit_status], list(0L)) - expect_true(file.exists(file.path(out_dir, files["expidf"]))) - expect_true(file.exists(file.path(out_dir, files["bsmt_idf"]))) - expect_true(file.exists(file.path(out_dir, files["bsmt_csv"]))) - expect_true(file.exists(file.path(out_dir, files["bsmt_out"]))) - expect_true(file.exists(file.path(out_dir, files["bsmt_audit"]))) - unlink(c(path_base, out_dir), recursive = TRUE) - - # can run Slab - path_slab <- copy_eplus_example(8.8, "5ZoneAirCooledWithSlab.idf") - expect_error(energyplus(path_slab, NULL, out_dir, echo = FALSE)) - # modify the input in order to reduce the simulation time - l <- read_lines(path_slab) - l[grepl("IYRS: Number of years to iterate", string), string := "1,"] - l[grepl("ConvTol: Convergence Tolerance", string), string := "1;"] - write_lines(l, path_slab) - res_slab <- energyplus(path_slab, weather, out_dir, echo = FALSE) - expect_equal(length(res_slab$file), 57L) - expect_equal({files <- unlist(res_slab$file); files <- files[!is.na(files)]; length(files)}, 26L) - expect_equal(sum(!file.exists(file.path(out_dir, files))), 0L) - expect_equal(sort(unname(files[names(files) != "epw"])), list.files(out_dir, "5ZoneAirCooledWithSlab")) - expect_equal(res_slab$run[program == "Slab", exit_status], list(0L)) - expect_true(file.exists(file.path(out_dir, files["slab_ger"]))) - expect_true(file.exists(file.path(out_dir, files["slab_gtp"]))) - expect_true(file.exists(file.path(out_dir, files["slab_out"]))) - unlink(c(path_slab, out_dir), recursive = TRUE) + if(Sys.getenv("_EPLUSR_SKIP_TESTS_BASEMENT_") == "") { + # can run Basement + path_base <- copy_eplus_example(8.8, "LgOffVAVusingBasement.idf") + expect_error(energyplus(path_base, NULL, out_dir, echo = FALSE)) + # modify the input in order to reduce the simulation time + l <- read_lines(path_base) + l[grepl("IYRS: Maximum number of yearly iterations", string), string := "1;"] + write_lines(l, path_base) + res_base <- energyplus(path_base, weather, out_dir, design_day = TRUE, echo = FALSE) + expect_equal(length(res_base$file), 57L) + expect_equal({files <- unlist(res_base$file); files <- files[!is.na(files)]; length(files)}, 27L) + expect_equal(sum(!file.exists(file.path(out_dir, files))), 0L) + expect_equal(sort(unname(files[names(files) != "epw"])), list.files(out_dir, "LgOffVAVusingBasement")) + expect_equal(res_base$run[program == "Basement", exit_status], list(0L)) + expect_true(file.exists(file.path(out_dir, files["expidf"]))) + expect_true(file.exists(file.path(out_dir, files["bsmt_idf"]))) + expect_true(file.exists(file.path(out_dir, files["bsmt_csv"]))) + expect_true(file.exists(file.path(out_dir, files["bsmt_out"]))) + expect_true(file.exists(file.path(out_dir, files["bsmt_audit"]))) + unlink(c(path_base, out_dir), recursive = TRUE) + + # can run Slab + path_slab <- copy_eplus_example(8.8, "5ZoneAirCooledWithSlab.idf") + expect_error(energyplus(path_slab, NULL, out_dir, echo = FALSE)) + # modify the input in order to reduce the simulation time + l <- read_lines(path_slab) + l[grepl("IYRS: Number of years to iterate", string), string := "1,"] + l[grepl("ConvTol: Convergence Tolerance", string), string := "1;"] + write_lines(l, path_slab) + res_slab <- energyplus(path_slab, weather, out_dir, echo = FALSE) + expect_equal(length(res_slab$file), 57L) + expect_equal({files <- unlist(res_slab$file); files <- files[!is.na(files)]; length(files)}, 26L) + expect_equal(sum(!file.exists(file.path(out_dir, files))), 0L) + expect_equal(sort(unname(files[names(files) != "epw"])), list.files(out_dir, "5ZoneAirCooledWithSlab")) + expect_equal(res_slab$run[program == "Slab", exit_status], list(0L)) + expect_true(file.exists(file.path(out_dir, files["slab_ger"]))) + expect_true(file.exists(file.path(out_dir, files["slab_gtp"]))) + expect_true(file.exists(file.path(out_dir, files["slab_out"]))) + unlink(c(path_slab, out_dir), recursive = TRUE) + } # can convert eso to IP path_ip <- copy_eplus_example(8.8, "1ZoneUncontrolled.idf")