3434# ' per-species evaluation statistics, and \code{overlay_list}, a list of raster
3535# ' overlays used for plotting and inspection.
3636# ' @references
37- # ' Pinkert, S., Sica, Y. V., Winner, K., & Jetz, W. (2023). The potential of
38- # ' ecoregional range maps for boosting taxonomic coverage in ecology and
39- # ' conservation. Ecography, 12, e06794.
37+ # ' Pinkert, S., Sica, Y. V., Winner, K., & Jetz, W. (2023). The potential of
38+ # ' ecoregional range maps for boosting taxonomic coverage in ecology and
39+ # ' conservation. Ecography, 12, e06794. \doi{10.1111/ecog.06794}
40+ # ' @seealso \code{\link{get_range}}() to generate the range maps being
41+ # ' evaluated, and \code{\link{cv_range}}() for cross-validation against the
42+ # ' original occurrence data instead of external validation data.
4043# ' @example inst/examples/evaluate_range_help.R
4144# ' @importFrom terra rast ext crs project aggregate rasterize crop extend resample values classify ncol nrow plot
4245# ' @importFrom sf st_read st_as_sf st_union st_drop_geometry st_transform
4346# ' @importFrom grDevices dev.off pdf
44- # ' @importFrom graphics legend par
47+ # ' @importFrom graphics legend
4548# ' @export
4649evaluate_range <- function (root_dir = NULL ,
4750 valData_dir = NULL ,
@@ -143,35 +146,33 @@ evaluate_range <- function(root_dir = NULL,
143146 ))
144147 }
145148
146- cat(" -Note-" , " \n " )
147149 if (valData_type == " TIFF" ) {
148150 f.list.matches <- intersect(f.list.eco , basename(f.list.valRM ))
149- cat(
150- sprintf(
151- paste(
152- " %.2f%% (%d) of the species names of ecoregions" ,
153- " match with names of the validation data files"
154- ),
155- 100 * length(f.list.matches ) / length(f.list.valRM ),
156- length(f.list.matches )
157- )
151+ match_msg <- sprintf(
152+ paste(
153+ " %.2f%% (%d) of the species names of ecoregions" ,
154+ " match with names of the validation data files"
155+ ),
156+ 100 * length(f.list.matches ) / length(f.list.valRM ),
157+ length(f.list.matches )
158158 )
159-
160159 } else {
161160 f.list.matches <- intersect(f.list.eco , f.list.valRM )
162- cat(
163- sprintf(
164- paste(
165- " %.2f%% (%d) of the species names of ecoregions" ,
166- " match with those in the validation data column 'sci_name'"
167- ),
168- 100 * length(f.list.matches ) / length(f.list.valRM ),
169- length(f.list.matches )
170- )
161+ match_msg <- sprintf(
162+ paste(
163+ " %.2f%% (%d) of the species names of ecoregions" ,
164+ " match with those in the validation data column 'sci_name'"
165+ ),
166+ 100 * length(f.list.matches ) / length(f.list.valRM ),
167+ length(f.list.matches )
171168 )
172169 }
173170
174- cat(" ------" , " \n " )
171+ if (isTRUE(verbose )) {
172+ message(" -Note-" )
173+ message(match_msg )
174+ message(" ------" )
175+ }
175176
176177 df.eval <- data.frame (
177178 species = f.list.matches ,
@@ -188,7 +189,7 @@ evaluate_range <- function(root_dir = NULL,
188189
189190 # Process each species
190191 for (i in seq_along(f.list.matches )) {
191- if (verbose ) cat (i , " Species: " , f.list.matches [i ], " \n " )
192+ if (isTRUE( verbose )) message (i , " Species: " , f.list.matches [i ])
192193
193194 if (is.null(mask )) {
194195 domain.raster <- NULL
@@ -321,7 +322,7 @@ evaluate_range <- function(root_dir = NULL,
321322 df.eval $ Sen_ecoRM [i ] + df.eval $ Spec_ecoRM [i ] - 1
322323
323324 # Plot the overlay raster
324- if (verbose && print_map ) {
325+ if (isTRUE( verbose ) && print_map ) {
325326
326327 if (! dir.exists(file.path(root_dir , " eval_output" ))) {
327328 dir.create(file.path(root_dir , " eval_output" ))
@@ -331,11 +332,10 @@ evaluate_range <- function(root_dir = NULL,
331332 colors <- c(" gray" , " red" , " blue" , " purple" )
332333 breaks <- c(- 0.5 , 0.5 , 1.5 , 2.5 , 3.5 )
333334
334- pdf(file = file.path(root_dir ," eval_output" ,
335+ grDevices :: pdf(file = file.path(root_dir ," eval_output" ,
335336 paste0(" Evaluation_map_" , f.list.matches [i ], " .pdf" )),
336337 height = (11 * aspect.r )+ 3 , width = 11
337338 )
338- par(mfrow = c(1 , 1 ))
339339 terra :: plot(
340340 overlay.raster ,
341341 col = colors ,
@@ -352,7 +352,7 @@ evaluate_range <- function(root_dir = NULL,
352352 )
353353
354354 # Adding a legend
355- legend(" bottomright" ,
355+ graphics :: legend(" bottomright" ,
356356 legend = c(
357357 " Abs in both (TA)" ,
358358 " Pres in ecoRM only (FP)" ,
@@ -364,22 +364,22 @@ evaluate_range <- function(root_dir = NULL,
364364 box.col = NA ,
365365 inset = c(0 ,0.1 )
366366 )
367- dev.off()
367+ grDevices :: dev.off()
368368 }
369369 }
370370
371- if (verbose ) {
372- cat(" Cross-species mean Prec & Sensitivity:" ,
371+ if (isTRUE(verbose )) {
372+ message(
373+ " Cross-species mean Prec & Sensitivity: " ,
373374 round(
374- mean(rowMeans(df.eval [, c(" Prec_ecoRM" , " Sen_ecoRM" )],na.rm = TRUE )),
375- digits = 2 ),
376- " \n "
375+ mean(rowMeans(df.eval [, c(" Prec_ecoRM" , " Sen_ecoRM" )], na.rm = TRUE )),
376+ digits = 2 )
377377 )
378378 }
379379
380- if (print_map ) {
381- cat (" ### Maps have been saved to:" ,
382- file.path(root_dir , " eval_output" ), " ###\n " )
380+ if (isTRUE( verbose ) && print_map ) {
381+ message (" ### Maps have been saved to: " ,
382+ file.path(root_dir , " eval_output" ), " ###" )
383383 }
384384
385385 output <- list (df_eval = df.eval , overlay_list = overlay.list )
0 commit comments