Search code examples
rajaxinstallationhtmlunitrjava

Cannot install htmlunit in R due to problem with Java


I wanted to scrape some sites that run AJAX and I found out about htmlunit. However it's been impossible to install this package. When I run this command:

install.packages("htmlunit", repos = "https://cinc.rud.is")

This is what is returned:

Error : package 'rJava' could not be loaded
Erreur : le chargement a échoué
Exécution arrêtée
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/jonah/Documents/R/win-library/3.6/htmlunitjars'
Warning in install.packages :
  installation of package ‘htmlunitjars’ had non-zero exit status
ERROR: dependency 'htmlunitjars' is not available for package 'htmlunit'
* removing 'C:/Users/jonah/Documents/R/win-library/3.6/htmlunit'
Warning in install.packages :
  installation of package ‘htmlunit’ had non-zero exit status

My rJava library loads just fine on its own. I've searched stackoverflow and tried many of the solutions but they don't seem to work. I've tried setting Java home to my Java directory using Sys.setenv(JAVA_HOME='C:\Program Files\Java\jre1.8.0_241').

I've also triple checked to make sure I'm running the same 64-bit version as my computer, reinstalled it multiple times, reinstalled R, specified R library in my windows environment variables, tried installing it through github using "remotes", none seem to work. The same error message appears. I don't get it, can someone help? Otherwise I'll have to look for a different way to deal with AJAX.


Solution

  • Welcome to the community. Try this please & let me know what happens:

    install.packages("htmlunit",  repos = "https://cinc.rud.is", INSTALL_opts="--no-multiarch")
    
    #then
    library(rJava)
    library(htmlunitjars)
    library(rvest)
    library(xml2)
    library(htmlunit)
    
    #all of the functions from namespaces of htmlunit will appear when you do this --> htmlunit::
    

    Dependency packages are pain in the back, especially those with Java.