.onLoad failed in loadNamespace() for 'rJava' when installing a package - r

I have a package "javaOnLoadFailed" (just a minimal package for testing my issue, hence the weird name) which imports rJava. I get 'rJava' errors when I try to either check() or install() the package, even though require(rJava) itself works fine.
install() gives the following errors:
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)
I am using R 3.2.0 from within Architect, with sessionInfo():
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] devtools_1.7.0.9000 rj_2.0.3-2
loaded via a namespace (and not attached):
[1] tools_3.2.0 rj.gd_2.0.0-1

The Java environment variable is empty
> Sys.getenv('JAVA')
[1] ""
Based on a suggestion, I tried setting the JAVA environment variable to point to the 64 Bit version of Java (because I am running R 64 bit, as you could see from the sessionInfo, but that doesn't work:
> Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/adb2018/Documents/R/win-library/3.2/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/adb2018/Documents/R/win-library/3.2/javaOnloadFailed'
Error: Command failed (1)
I then tried to set the JAVA environment variable such that it points to the 32 bit version of Java on my system, and then it works!
> Sys.setenv(JAVA_HOME='C:\\Program Files (x86)\\Java\\jre1.8.0_45\\')
> install()
Installing javaOnloadFailed
"C:/Program Files/R/R-3.2.0/bin/x64/R" --no-site-file --no-environ --no-save \
--no-restore CMD INSTALL \
"C:/Projects/stackoverflow/javaOnloadFailed/javaOnLoadFailed" \
--library="C:/Users/adb2018/Documents/R/win-library/3.2" --with-keep.source \
--install-tests
* installing *source* package 'javaOnloadFailed' ...
** R
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
*** arch - x64
* DONE (javaOnloadFailed)
[INFO] Updating the R environment index started...
[INFO] The R environment index was updated successfully.
I don't quite understand why I need to point to Java 32 bit to make R 64 bit work, but that's what seems to be the case.
By the way, don't stumble over my package name "javaOnLoadFailed". I just created a minimal package with that name to test the problem.

Many packages fail install because they are not meant to run on i386 platform but the standard installation process tries to do that. Users waste a lot of time with jvm.dll and PATH and JAVA_HOME when the real fix is to force the installed to just forget about i386. Use option for install.packages. (this also works when drat library is used. (credit goes to Dason)
install.packages("SqlRender",INSTALL_opts="--no-multiarch")

I have found the same problem when trying to install a package only available in Github.
This solved for me:
devtools::install_github("snowflakedb/dplyr-snowflakedb", INSTALL_opts=c("--no-multiarch"))

Remember the problem is that R doesn't know where jvm.dll is. When you set JAVA_HOME use the path of the directory that contains the dll file.
You can find it in bin\client or bin\server.
The command then becomes:
Sys.setenv(JAVA_HOME='C:\\Program Files\\Java\\jre1.8.0_45\\bin\\client')

I tried remove the JAVA_HOME system variable and it works. So that when you launch R, Sys.getenv("JAVA_HOME") gives you "".

Related

Error: package or namespace load failed for 'treesnip'

When trying to install the treesnip package from github using remotes::install_github("curso-r/treesnip"), I get the following error:
remotes::install_github("curso-r/treesnip")
Downloading GitHub repo curso-r/treesnip#HEAD
WARNING: Rtools is required to build R packages, but is not currently installed.
Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.
√ checking for file 'C:\Users\SAR.V-LOG\AppData\Local\Temp\RtmpENiM7Q\remotes38701dfb49f3\curso-r-treesnip-c70a89b/DESCRIPTION' (375ms)
- preparing 'treesnip': (736ms)
√ checking DESCRIPTION meta-information ...
- checking for LF line-endings in source and make files and shell scripts
- checking for empty or unneeded directories
Removed empty directory 'treesnip/.github/workflows'
Removed empty directory 'treesnip/.github'
NB: this package now depends on R (>= 3.5.0)
WARNING: Added dependency on R >= 3.5.0 because serialized objects in serialize/load version 3 cannot be read in older versions of R. File(s) containing such objects: 'treesnip/inst/benchmark_parallel_processing_vignette.rds'
- building 'treesnip_0.1.0.tar.gz'
* installing *source* package 'treesnip' ...
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'treesnip'
finding HTML links ... done
add_boost_tree_catboost html
add_boost_tree_lightgbm html
add_decision_tree_tree html
multi_predict._catboost.Model html
multi_predict._lgb.Booster html
predict_lightgbm_classification_class html
predict_lightgbm_classification_prob html
predict_lightgbm_classification_raw html
predict_lightgbm_regression_numeric html
train_catboost html
train_lightgbm html
train_tree html
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
*** arch - i386
Error: package or namespace load failed for 'treesnip':
.onLoad failed in loadNamespace() for 'treesnip', details:
call: NULL
error: The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x'
error: loading failed
running stopped
*** arch - x64
Error: package or namespace load failed for 'treesnip':
.onLoad failed in loadNamespace() for 'treesnip', details:
call: NULL
error: The values passed to `set_encoding()` are missing arguments: 'allow_sparse_x'
Fejl: loading failed
running stopped
ERROR: loading failed for 'i386', 'x64'
* removing 'C:/Users/SAR.V-LOG/OneDrive - VELUX/Documents 1/R/R-4.0.2/library/treesnip'
Error: Failed to install 'treesnip' from GitHub:
(converted from warning) installation of package ‘C:/Users/SAR~1.V-L/AppData/Local/Temp/RtmpENiM7Q/file38706c2c7239/treesnip_0.1.0.tar.gz’ had non-zero exit status
my sessionInfo():
sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18362)
Matrix products: default
locale:
[1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 LC_MONETARY=Danish_Denmark.1252
[4] LC_NUMERIC=C LC_TIME=Danish_Denmark.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] compiler_4.0.2 tools_4.0.2
I works fine when running on another PC.
I also tried changing the library location to C:/Users/SAR.V-LOG/, but that didn't help either.
Further I tried to provide INSTALL_opts = "--no-test-load". When I do that the installation finished wihtout errors, but when I try to load the library using library(treesnip) I get the same error: The values passed to set_encoding() are missing arguments: 'allow_sparse_x'
Do you know what is causing this error and how I can fix it?
treesnip is fixed. It now depends on parsnip (>= 0.1.3.9000) https://github.com/curso-r/treesnip/commit/902a33d9f156c10da6dbe1bd9cccb65926077197
Try using parsnip 0.1.3 (not the development version in this case). It looks like 0.1.3.9000 has some breaking changes coming that will be handled in a new version of parsnip-adjacent packages.
The warning message indicates:
Please download and install Rtools 4.0 from https://cran.r-project.org/bin/windows/Rtools/.
You may need to upgrade your Rtools, which can be done here: https://cran.r-project.org/bin/windows/Rtools/
Let me know if this fixes your problem.
Also I have added a GitHub Issue Here: https://github.com/tidymodels/parsnip/issues/376

Capture R output when running Rcmd.exe

I have a line of code to capture the output of the version of Java installed:
version <- system2("java","-version", stdout=TRUE)
However, if I include that line of code when creating a package in the .onLoad function, I run into a problem when building.
.onLoad <- function(libname, pkgname){
version <- system2("java","-version", stdout=TRUE)
if(length(version)==0){
stop("Missing version")
}
}
Using the default RStudio "Clean and Rebuild", I can see both that the output is shown in the command line (the Java parts), and that the code then has the error showing the output was length 0:
==> Rcmd.exe INSTALL --preclean --no-multiarch --with-keep.source testpackage
* installing to library 'C:/Users/JNolis2/Documents/R/win-library/3.5'
* installing source package 'testpackage' ...
** R
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'testpackage'
finding HTML links ... hello html
done
** building package indices
** testing if installed package can be loaded
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Error: package or namespace load failed for 'testpackage':
.onLoad failed in loadNamespace() for 'testpackage', details:
call: fun(libname, pkgname)
error: Missing version
Error: loading failed
Execution halted
ERROR: loading failed
removing 'C:/Users/JNolis2/Documents/R/win-library/3.5/testpackage'
In R CMD INSTALL
Exited with status 1.
How can I ensure the output is captured even during this step?

Error in installing Tabulizer

Using the instructions described in github and installing Java accordingly with Chocolatey -- plus installing rJava and setting the path in R with Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jdk1.8.0_131")-- I've done the following in R:
library(ghit)
library(git2r)
ghit::install_github(c("leeper/tabulizerjars", "leeper/tabulizer"), INSTALL_opts = "--no-multiarch", dependencies = c("Depends", "Imports"))
Which is the solution provided in this answer. I get the following error:
Error in git2r::init(d) :
Error in 'git2r_repository_init': Unable to init repository
Setting the option VERBOSE = TRUE in install_github I get the following additional output:
Parsing reponame for 'leeper/tabulizerjars'...
Creating local git repository for tabulizerjars in C:\Users\JOOCAR~1\AppData\Local\Temp\RtmpgnitDP\tabulizerjars1643e0126f5...
Error in git2r::init(d) :
Error in 'git2r_repository_init': Unable to init repository
I read this answer and it seems that it has to do with my username, which is spaced and has accents. But how do I configure this?
edit: 6/4/2017 1:57 am
Following user #jaySf answer, I run part of the code of his answer (since I've already installed rJava and devtools):
library(rJava) # load and attach 'rJava' now
devtools::install_github("ropensci/tabulizer", args="--no-multiarch")
And got the following error:
> library(rJava) # load and attach 'rJava' now
> devtools::install_github("ropensci/tabulizer", args="--no-multiarch")
Downloading GitHub repo ropensci/tabulizer#master
from URL https://api.github.com/repos/ropensci/tabulizer/zipball/master
Installing tabulizer
Downloading GitHub repo ropensci/tabulizerjars#master
from URL https://api.github.com/repos/ropensci/tabulizerjars/zipball/master
Installing tabulizerjars
"C:/R-34~1.0/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL "C:/Users/Joo \
Caos/AppData/Local/Temp/Rtmpgh9eJi/devtoolsb3c50925145/ropensci-tabulizerjars-c6cc40e" --library="C:/R-3.4.0/library" --install-tests
* installing *source* package 'tabulizerjars' ...
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
*** arch - i386
Error: package or namespace load failed for 'tabulizerjars':
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/R-3.4.0/library/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/R-3.4.0/library/tabulizerjars'
Installation failed: Command failed (1)
"C:/R-34~1.0/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL "C:/Users/Joo \
Caos/AppData/Local/Temp/Rtmpgh9eJi/devtoolsb3c4a2835ec/ropensci-tabulizer-a38d957" --library="C:/R-3.4.0/library" --install-tests --no-multiarch
ERROR: dependency 'tabulizerjars' is not available for package 'tabulizer'
* removing 'C:/R-3.4.0/library/tabulizer'
Installation failed: Command failed (1)
I believe that I might have a problem with my username in the file directory path, but I'm not sure. I tried using install_github with ggplot2 --`install_github("wch/ggplot2") -- and it worked fine. If my guess is correct, how can I edit the file path?
Problem solved
I was running R with both 32 bit and 64 bit files installed. I cannot clearly state what were the problems in doing this, since as I ran Sys.getenv("R_ARCH") it returned x64 previously, but when I uninstalled the 32 bit files, it ran perfectly well with #jaySf code.
Follow these steps in given order should work:
install.packages("rJava")
library(rJava) # load and attach 'rJava' now
install.packages("devtools")
devtools::install_github("ropensci/tabulizer", args="--no-multiarch")
I'm using R 3.4.0 on win64, and described the procedure in a former answer.
install.packages("rJava")
library(rJava) # load and attach 'rJava' now
install.packages("devtools")
#run below package first..
devtools::install_github("ropensci/tabulizerjars", args="--no-multiarch")
devtools::install_github("ropensci/tabulizer", args="--no-multiarch")
You might try:
devtools::install_github("ropensci/tabulizerjars", INSTALL_opts = c("--no-multiarch"))
devtools::install_github("ropensci/tabulizer", INSTALL_opts = c("--no-multiarch"))

Error in installing R Package "SqlRender"

I am new to R - Programming, I am trying to run "install_github("ohdsi/SqlRender")" on windows 7, 64-bit with jdk 7 (64- bit) and R version 3.1.2 and R-GUI (64-bit).
I am getting the following error:
> library("devtools")
Warning message:
package ‘devtools’ was built under R version 3.1.3
> install_github("ohdsi/SqlRender")
Downloading github repo ohdsi/SqlRender#master
Installing SqlRender
"C:/PROGRA~1/R/R-31~1.2/bin/x64/R" --no-site-file --no-environ --no-save -- no-restore CMD INSTALL \
"C:/Users/PPingali/AppData/Local/Temp/RtmpMtqVJl/devtools1318104472eb/OHDSI- SqlRender-cc551a2" \
--library="C:/Users/PPingali/Documents/R/win-library/3.1" --install-tests
* installing *source* package 'SqlRender' ...
** R
** inst
** tests
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
*** arch - i386
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/PPingali/Documents/R/win- library/3.1/rJava/libs/i386/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
Error: loading failed
Execution halted
*** arch - x64
ERROR: loading failed for 'i386'
* removing 'C:/Users/PPingali/Documents/R/win-library/3.1/SqlRender'
Error: Command failed (1)
Please help me out in fixing this issue...
Thanks in advance.....
....................................................................
rJava package got installed perfectly...
when i run
library(rJava)
gives me no error.....
install.packages("SqlRender",INSTALL_opts = "--no-multiarch")
for some reason checks bost 32 and 64bit versions. even though I have correct x64 version of Java 1.8, R it still failed check i386 step. the INSTALL_opts flaf seems to bypass and then no issue

Error installing R package atSNP

I am trying to install an R package atSNP from https://github.com/chandlerzuo/atSNP. According to the documentation, this is how it is installed:
> library(devtools)
> install_github("chandlerzuo/atSNP")
But I get the following error:
Downloading github repo chandlerzuo/atSNP#master
Installing atSNP
Skipping 2 packages not available: GenomicRanges, motifStack
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ --no-save --no-restore CMD INSTALL \
'/private/var/folders/vt/nnrr0hts2h1bk6stsg4mt2xw0000gn/T/Rtmpzjo43z/devtoolsd9a33b03bdb4/chandlerzuo-atSNP-8cbe50e' \
--library='/Library/Frameworks/R.framework/Versions/3.2/Resources/library' --install-tests
* installing *source* package ‘atSNP’ ...
** libs
make: Nothing to be done for `all'.
installing to /Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs
** R
** data
** tests
** preparing package for lazy loading
No methods found in "IRanges" for requests: sapply
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
No methods found in "IRanges" for requests: sapply
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so, 6): no suitable image found. Did find:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP’
Error: Command failed (1)
This is the session info:
> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.10 (Yosemite)
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] grid stats4 parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] motifStack_1.12.0 Biostrings_2.36.1 XVector_0.8.0 ade4_1.7-2 MotIV_1.24.0 grImport_0.9-0
[7] XML_3.98-1.2 GenomicRanges_1.20.4 GenomeInfoDb_1.4.0 IRanges_2.2.2 S4Vectors_0.6.0 BiocGenerics_0.14.0
[13] devtools_1.8.0
loaded via a namespace (and not attached):
[1] magrittr_1.5 GenomicAlignments_1.4.1 zlibbioc_1.14.0 BiocParallel_1.2.2 BSgenome_1.36.0
[6] lattice_0.20-31 stringr_1.0.0 httr_0.6.1 tools_3.2.0 seqLogo_1.34.0
[11] lambda.r_1.1.7 futile.logger_1.4.1 git2r_0.10.1 rversions_1.0.0 digest_0.6.8
[16] rtracklayer_1.28.4 futile.options_1.0.0 bitops_1.0-6 RCurl_1.95-4.6 memoise_0.2.1
[21] rGADEM_2.16.0 stringi_0.4-1 Rsamtools_1.20.4
As you can see, I have installed & attached both packages GenomicRanges & motifStack and still the installation message says they are not available. I have tried uninstalling & reinstalling both the packages but I still get the same error. Any suggestions will be appreciated.
UPDATE: I followed the suggestion below and still getting the following errors:
* installing to library ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library’
* installing *source* package ‘atSNP’ ...
** libs
make: Nothing to be done for `all'.
installing to /Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs
** R
** data
** preparing package for lazy loading
No methods found in "IRanges" for requests: sapply
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
No methods found in "IRanges" for requests: sapply
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so, 6): no suitable image found. Did find:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP/libs/atSNP.so: unknown file type, first eight bytes: 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/Library/Frameworks/R.framework/Versions/3.2/Resources/library/atSNP’
Thanks
You can download the source package from the github website and install it. This gives no error on my Mac. In the terminal, type
git clone git://github.com/chandlerzuo/atSNP.git
R CMD INSTALL atSNP

Resources