I am using Posit Cloud and am having an interesting problem when trying to use the MaxEnt function from the Dismo package. When I run the MaxEnt function for the first time in a script e.g.,
# Fit the MaxEnt model
maxent_model <- maxent(
x = predictor,
p = data.matrix(presence_points),
a = background_points
)
then it works as expected with the following output:
> Jan 20, 2025 10:11:15 AM java.util.prefs.FileSystemPreferences$1 run
> INFO: Created user preferences directory.
However, if I reload the script and run the same thing I get the following error:
Error in .jcheck(silent = TRUE) :
No running JVM detected. Maybe .jinit() would help.
If I run .jinit() as suggested I get an updated error:
Error in .local(x, p, ...) : java.lang.ClassNotFoundException
If I am to copy the script to a new project, it works fine again. If I run system("java -version") into the reloaded script, it appears that java is loading okay.
system("java -version")
openjdk version "11.0.22" 2024-01-16
OpenJDK Runtime Environment (build 11.0.22+7-post-Ubuntu-0ubuntu220.04.1)
OpenJDK 64-Bit Server VM (build 11.0.22+7-post-Ubuntu-0ubuntu220.04.1, mixed mode, sharing)
I've also tried the following:
> .jinit()
[1] 0
> .jclassPath()
[1] "/cloud/lib/x86_64-pc-linux-gnu-library/4.3/rJava/java"
> .jnew("java/lang/String", "Hello, Java in R!")
[1] "Java-Object{Hello, Java in R!}"
all of which suggest to me that java is operational (although I have limited experience).
I have also tried uploading MaxEnt and the associated maxent.jar to my file directory and adding it using:
.jaddClassPath("/maxent/maxent.jar")
I'd be grateful if anyone has any thoughts. Note: Rstudio-cloud tag created because I don't have the reputation to create posit-cloud. I believe Rstudio-cloud is the previous name.