Skip to content

Commit

Permalink
action & coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
stangandaho committed Apr 23, 2024
1 parent 454a669 commit 652c5f4
Show file tree
Hide file tree
Showing 7 changed files with 426 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'release'}
#- {os: ubuntu-latest, r: 'release'}
#- {os: windows-latest, r: '3.6'}
#- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
#- {os: ubuntu-latest, r: 'oldrel-1'}
Expand All @@ -29,7 +29,7 @@ jobs:
CRAN: ${{ matrix.config.rspm }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand All @@ -38,7 +38,7 @@ jobs:
- uses: r-lib/actions/setup-pandoc@v2

- name: Cache R packages
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: ${{ env.R_LIBS_USER }}
key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: r-lib/actions/setup-r@v2
with:
Expand Down
3 changes: 1 addition & 2 deletions R/nm_boyce.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@
#' presence_predicted <- sqrt(runif(100))
#' contrast <- runif(1000)
#' nm_boyce(presence_predicted, contrast)
#' contBoyce2x(presence_predicted, contrast)
#' presence_weight <- c(rep(1, 10), rep(0.5, 90))
#' nm_boyce(presence_predicted, contrast, presence_weight=presence_weight)
#'

nm_boyce <- function(
presence_predicted,
contrast,
numBins = 101,
num_bins = 101,
bin_width = 0.1,
presence_weight = rep(1, length(presence_predicted)),
contrast_weight = rep(1, length(contrast)),
Expand Down
7 changes: 3 additions & 4 deletions man/nm_boyce.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions tests/testthat/test-nm_find_hcv.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,19 @@ testthat::test_that("Test find highly correlated variables", {
weigth <- abs(rnorm(150, 56.2, 11.4))
glucose_rate <- runif(150, .2, .6)

test_data <- data.frame(age, heigth, weigth, glucose_rate) %>%
cor()
samp_data <- data.frame(age, heigth, weigth, glucose_rate)
test_cor <- samp_data%>% cor()

# highly correlated variables
testthat::expect_equal(class(nm_find_hcv(x = test_data)), "character")
testthat::expect_equal(class(nm_find_hcv(x = test_cor)), "character")
testthat::expect_equal(class(nm_find_hcv(x = test_cor, verbose = TRUE)), "character")


samp_data$na_v <- sample(x = rep(c(1, NA, 5, 2, 5,9), 200), size = 150)
test_cor <- samp_data%>% cor()

expect_error(nm_find_hcv(x = test_cor))
expect_error(nm_find_hcv(x = c(12, 45, 6)))

rm(samp_data, test_cor)
})
27 changes: 23 additions & 4 deletions tests/testthat/test-nm_match_raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,37 @@ test_that("test for nm_match_raster", {
library(terra)

env_layers_path <- paste0(system.file("extdata", package = "nimo"), "/env_layers")
env_layers_path <- list.files(env_layers_path, full.names = TRUE)[1:2]
env_layers_path <- list.files(env_layers_path, pattern = ".tif$", full.names = TRUE)[1:2]

target <- terra::rast(env_layers_path[1]) # reference raster to get properties from
to_match <- terra::rast(env_layers_path[2]) # raster that will inherit properties

#
new_dnw <- nm_match_raster(to_match = to_match, target = target)

expect_true(class(new_dnw) == "SpatRaster")
expect_error(
nm_match_raster(to_match = to_match, target = target, method = "linear")
)

expect_error(
nm_match_raster(to_match = to_match, target = "", method = "linear")
)

#
new_dnw <- nm_match_raster(to_match = to_match, target = target,
save_file = T, file_name = "test.tif")
expect_true(file.exists(paste0(getwd(), "/test.tif")))
unlink(paste0(getwd(), "/test.tif"), recursive = T)

#
new_dnw <- nm_match_raster(to_match = to_match, target = target,
save_file = T)
save_path <- paste0(
dirname(terra::sources(to_match)), "/",
gsub("\\..*$", "", basename(terra::sources(to_match))), "_matched.tif"
)
expect_true(file.exists(save_path))
unlink(save_path, recursive = T)


rm(env_layers_path, target, to_match, new_dnw)
rm(env_layers_path, target, to_match, new_dnw, save_path)
})
Loading

0 comments on commit 652c5f4

Please sign in to comment.