if(dir.exists(paste(Sys.getenv("PROGRAMFILES"), "\\Java\\", sep = ""))){
Javapath <- paste(Sys.getenv("PROGRAMFILES"), "\\Java\\", sep = "")
Javapath <- paste(Javapath, list.files(path = Javapath, pattern = "jdk"), "\\",sep = "")
if(grepl("jdk", Javapath)){
options(java.home=Javapath[which.max(gsub(".*jdk[0-9]+\\.[0-9]+\\.[0-9]+_|\\\\$", "", Javapath))])
}else{
Javapath <- paste(Sys.getenv("PROGRAMFILES"), "\\Java\\", sep = "")
Javapath <- paste(Javapath, list.files(path = Javapath, pattern = "jre"), "\\",sep = "")
options(java.home=Javapath[which.max(gsub(".*jre[0-9]+\\.[0-9]+\\.[0-9]+_|\\\\$", "", Javapath))])
}
}else if(dir.exists(paste(Sys.getenv("PROGRAMFILES(x86)"), "\\Java\\", sep = ""))){
Javapath <- paste(Sys.getenv("PROGRAMFILES(x86)"), "\\Java\\", sep = "")
Javapath <- paste(Javapath, list.files(path = Javapath, pattern = "jre"), "\\",sep = "")
options(java.home=Javapath[which.max(gsub(".*jre[0-9]+\\.[0-9]+\\.[0-9]+_|\\\\$", "", Javapath))])
}
Может быть, вы можете попытаться установить параметры (java.home = "путь к Java")