@@ -3,8 +3,9 @@ test_that("prepClimateLayers works for multiple variable types", {
33 skip_on_ci() # # needs to authorize googldrive package for downloads
44 skip_if_not_installed(" archive" )
55 skip_if_not_installed(" googledrive" )
6+ skip_if_not_installed(" withr" )
67
7- dPath <- file.path(tempdir(), " test_prepClimateLayers " )
8+ dPath <- withr :: local_tempdir( " test_prepClimateLayers_ " )
89 climateType <- " historical"
910 climatePath <- file.path(dPath , " climate" ) | > reproducible :: checkPath(create = TRUE )
1011 climatePathOut <- file.path(climatePath , " outputs" ) | > reproducible :: checkPath(create = TRUE )
@@ -66,11 +67,10 @@ test_that("prepClimateLayers works for multiple variable types", {
6667 # # test with all parallel backends
6768 climateRasters <- list ()
6869 for (backend in .parallelBackends ) {
69- withr :: with_options(
70- list (climateData.parallel.backend = backend ), {
70+ withr :: with_options(list (climateData.parallel.backend = backend ), {
7171 climateRasters [[backend ]] <- prepClimateLayers(
7272 climateVarsList = climateVariables ,
73- srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
73+ srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
7474 dstdir = climatePathOut , # # 'dst' is the place for intermediate + final outputs
7575 tile = tileIDs ,
7676 gcm = GCM ,
@@ -91,20 +91,18 @@ test_that("prepClimateLayers works for multiple variable types", {
9191 skip_if_not_installed(" SpaDES.tools" )
9292
9393 studyArea <- SpaDES.tools :: randomStudyArea(size = 1e10 )
94- rasterToMatch <- terra :: rast(studyArea , resolution = 250 ) | >
95- terra :: rasterize(studyArea , y = _)
94+ rasterToMatch <- terra :: rast(studyArea , resolution = 250 ) | > terra :: rasterize(studyArea , y = _)
9695
9796 # # test with all parallel backends
9897 climateRasters <- list ()
9998 for (backend in .parallelBackends ) {
100- withr :: with_options(
101- list (climateData.parallel.backend = backend ), {
99+ withr :: with_options(list (climateData.parallel.backend = backend ), {
102100 # # spurious warning:
103101 # # attribute variables are assumed to be spatially constant throughout all geometries
104102 climateRastersStudyArea <- suppressWarnings({
105103 prepClimateLayers(
106104 climateVarsList = climateVariables ,
107- srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
105+ srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
108106 dstdir = climatePathOut , # # 'dst' is the place for intermediate + final outputs
109107 # tile = tileIDs, ## when passing `studyArea`/`rasterToMatch` then `tile` isn't needed
110108 gcm = GCM ,
@@ -122,16 +120,17 @@ test_that("prepClimateLayers works for multiple variable types", {
122120 })
123121 }
124122
125- unlink( dPath , recursive = TRUE )
123+ withr :: deferred_run( )
126124})
127125
128126test_that(" prepClimateLayers properly handles unordered tileIDs" , {
129127 skip_on_cran()
130128 skip_on_ci() # # needs to authorize googldrive package for downloads
131129 skip_if_not_installed(" archive" )
132130 skip_if_not_installed(" googledrive" )
131+ skip_if_not_installed(" withr" )
133132
134- dPath <- file.path(tempdir(), " test_prepClimateLayers " )
133+ dPath <- withr :: local_tempdir( " test_prepClimateLayers_ " )
135134 climateType <- " historical"
136135 climatePath <- file.path(dPath , " climate" ) | > reproducible :: checkPath(create = TRUE )
137136 climatePathOut <- file.path(climatePath , " outputs" ) | > reproducible :: checkPath(create = TRUE )
@@ -153,7 +152,7 @@ test_that("prepClimateLayers properly handles unordered tileIDs", {
153152
154153 climateRasters <- prepClimateLayers(
155154 climateVarsList = climateVariables ,
156- srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
155+ srcdir = climatePath , # # 'src' is the place for raw inputs, downloaded from Google Drive
157156 dstdir = climatePathOut , # # 'dst' is the place for intermediate + final outputs
158157 tile = tileIDs ,
159158 gcm = NULL ,
@@ -168,5 +167,5 @@ test_that("prepClimateLayers properly handles unordered tileIDs", {
168167 expect_s4_class(x , " SpatRaster" )
169168 })
170169
171- unlink( dPath , recursive = TRUE )
170+ withr :: deferred_run( )
172171})
0 commit comments