-
Notifications
You must be signed in to change notification settings - Fork 5
Description
I'm encountering an error when running the MaxEnt function in my R script with a specified biasFile. The script works fine without the biasFile argument, but fails with it. The error message suggests that a file cannot be opened because it does not exist. Here are the details:
SessionInfo
R version 4.3.3 (2024-02-29 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.utf8 LC_CTYPE=German_Germany.utf8 LC_MONETARY=German_Germany.utf8 LC_NUMERIC=C
[5] LC_TIME=German_Germany.utf8
time zone: Europe/Berlin
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] rJava_1.0-11 predicts_0.1-13 dismo_1.3-14 raster_3.6-26 sp_2.1-3 tidyterra_0.5.2 sf_1.0-16 lubridate_1.9.3 forcats_1.0.0
[10] stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.0 tidyverse_2.0.0 MASS_7.3-60.0.1
[19] geodata_0.5-9 terra_1.7-78
loaded via a namespace (and not attached):
[1] utf8_1.2.4 generics_0.1.3 class_7.3-22 KernSmooth_2.23-22 stringi_1.8.3 lattice_0.22-6 hms_1.1.3
[8] magrittr_2.0.3 grid_4.3.3 timechange_0.3.0 e1071_1.7-14 DBI_1.2.2 fansi_1.0.6 scales_1.3.0
[15] codetools_0.2-20 cli_3.6.2 rlang_1.1.3 units_0.8-5 munsell_0.5.1 withr_3.0.0 tools_4.3.3
[22] tzdb_0.4.0 colorspace_2.1-0 vctrs_0.6.5 R6_2.5.1 proxy_0.4-27 lifecycle_1.0.4 classInt_0.4-10
[29] pkgconfig_2.0.3 pillar_1.9.0 gtable_0.3.5 glue_1.7.0 Rcpp_1.0.12 tidyselect_1.2.1 rstudioapi_0.16.0
[36] compiler_4.3.3
Skript
library(terra)
library(geodata)
library(MASS)
library(rJava)
library(raster)
# Load climate data for Germany
clim <- worldclim_country("germany", "tmin", "C:/Users/XYZ/tmp")[[1]]
# Define occurrence data
occurrenceData <- tibble::tibble(
Longitude = c(8.14, 13.8, 12.1, 14.1, 11.2, 14.2, 7.17, 10.8, 15.0, 7.60),
Latitude = c(48.8, 52.4, 49.0, 52.5, 47.9, 52.1, 50.7, 50.6, 51.1, 48.0)
)
# Extract presence values
presenceValues <- terra::extract(clim, occurrenceData)
# Generate density estimate for bias file
dens <- kde2d(occurrenceData$Longitude, occurrenceData$Latitude, n = c(nrow(clim), ncol(clim)))
biasFile <- rast(raster(dens))
# Run MaxEnt model
meOutput <- MaxEnt(clim, occurrenceData, args = c('hinge=false', 'threshold=false', "biasfile=biasFile"))
Error Message
Error in file(con, "r") : cannot open the connection
In addition: Warning message:
In file(con, "r") :
cannot open file 'C:\Users\XYZ\AppData\Local\Temp\RtmpOQnOXT/maxent/2864878335/species.lambdas': No such file or directory
Expected Behavior:
The MaxEnt function should run successfully using the specified biasFile, without any file connection issues.
Actual Behavior:
The function fails with the above error message when the biasFile argument is included.
Additional Notes:
I also tried to specify the path to a local biasfile and received the same error message.
Any guidance on resolving this issue or insights into why the biasFile argument causes this error would be greatly appreciated.
Thank you for your assistance!