devtools::check() report error due to rJAVA - r

In Rstudio, I run devtools:check() in my project, and the following error occured
Error: .onLoad failed in loadNamespace() for 'rJava', details:
call: library.dynam("rJava", pkgname, libname)
error: DLL 'rJava' not found: maybe not installed for this architecture?
Before this error occur, I am pretty sure I successfully installed rJava using install.packages('rJava',type='source'), now I run .libPaths() and it returned
[1] "C:/Users/xxx/Documents/R/win-library/3.3" "C:/Program Files/R/R-3.3.1/library"
The rJava library I installed is in C:\Users\sunxd\Documents\R\win-library\3.3, and after I copy that into"C:/Program Files/R/R-3.3.1/library" it still does not work.
I could load rJava by library('rJava') anyway.
It seems that the problem is with different architecture, and I wonder why there should be different architecture on only one machine?
** running examples for arch 'x64' ... OK
Examples with CPU or elapsed time > 5s
user system elapsed
tuneParams 5.72 0 5.83
** found \donttest examples: check also with --run-donttest
* checking for unstated dependencies in 'tests' ... OK
* checking tests ...
** running tests for arch 'i386' ...
Running 'run-base.R' [17m]
Warning message:
running command '"C:/PROGRA~1/R/R-33~1.1/bin/i386/R" CMD BATCH --vanilla "run-base.R" "run-base.Rout"' had status 1

Related

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?

R: package installation trouble in Ubuntu

I'm running on Ubuntu 16.04 (on a Lenovo ThinkPak T450). I have installed R version 3.4.1, installed by following the instructions here via Rbloggers.
From here, I would like to start installing packages, but if I run R from the command line without root privileges, I cannot access a CRAN mirror. That is, when I run install.packages('dplyr') (or any install.packages('blah')) I get the following error
--- Please select a CRAN mirror for use in this session ---
Error: .onLoad failed in loadNamespace() for 'tcltk', details:
call: fun(libname, pkgname)
error: Can't find a usable init.tcl in the following directories:
/opt/anaconda1anaconda2anaconda3/lib/tcl8.5 ./lib/tcl8.5 ./lib/tcl8.5 ./library ./library ./tcl8.5.18/library ./tcl8.5.18/library
With that error, no CRAN mirror dialog box appears and hence no installation of packages. Note: this error does not happen when I start R with root privileges (i.e., start via > sudo R), but I do not want to install packages as root.
Thanks in advance for any help you can send my way!
Edit: Specifying the repo also results in error (in the file paths below, I replaced my user-name with user-name).
E.g.: install.packages('Rcpp',repos='http://cran.us.r-project.org') terminates with:
installing to /home/user-name/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘Rcpp’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/home/user-name/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs/Rcpp.so':
/home/user-name/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/libs/Rcpp.so: undefined symbol: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEED1Ev
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/user-name/R/x86_64-pc-linux-gnu-library/3.4/Rcpp’
E.g., install.packages('dplyr',repos='http://cran.us.r-project.org') terminates with:
installing to /home/user-name/R/x86_64-pc-linux-gnu-library/3.4/dplyr/libs
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/user-name/R/x86_64-pc-linux-gnu-library/3.4/bindrcpp/libs/bindrcpp.so':
/home/user-name/anaconda3/lib/R/bin/exec/../../lib/../.././libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /home/user-name/R/x86_64-pc-linux-gnu-library/3.4/bindrcpp/libs/bindrcpp.so)
ERROR: lazy loading failed for package ‘dplyr’
* removing ‘/home/user-name/R/x86_64-pc-linux-gnu-library/3.4/dplyr’
As pointed out by DirkEddelbuettel in the comments, the issue was a mixing of Anaconda and R. To fix this problem:
I uninstalled the R packages from Anaconda by first looking at > conda list and realizing that the package was r-base; hence running > conda remove r-base.
Next, by looking at the output of > which R, it was clear that we were still trying to execute from the ../anaconda3/bin/.. directory. I suspect there is a quick way to change this via an export or bashrc amendment (or something similar), but for me, the quickest work-around was to run > sudo apt-get install r-base r-base-dev, which took all of 0.2 seconds as they were already installed, but it did affect the directory which the system looks in to the appropriate one, for me this is /usr/bin/R/.
From here I've been able to install everything I've needed.
Note: Thinking back, I suspect the "mixing" happened when I installed rpy2 via conda.

Wrong version of Java is loaded during installation

I have a weird issue while trying to install packages which depend on Java/rJava on my 64-bit Windows 10:
> devtools::install_github("ropensci/tabulizer", INSTALL_opts = "--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:/PROGRA~1/R/R-34~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \
"C:/Users/binis/AppData/Local/Temp/Rtmpiw2khr/devtools4d7472ae39f9/ropensci-tabulizerjars-60b7cec" \
--library="C:/Users/binis/Documents/R/win-library/3.4" --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:/Users/binis/Documents/R/win-library/3.4/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/binis/Documents/R/win-library/3.4/tabulizerjars'
Installation failed: Command failed (1)
"C:/PROGRA~1/R/R-34~1.2/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \
"C:/Users/binis/AppData/Local/Temp/Rtmpiw2khr/devtools4d744e067cae/ropensci-tabulizer-3aad163" \
--library="C:/Users/binis/Documents/R/win-library/3.4" --install-tests
ERROR: dependency 'tabulizerjars' is not available for package 'tabulizer'
* removing 'C:/Users/binis/Documents/R/win-library/3.4/tabulizer'
Installation failed: Command failed (1)
Now I'm aware that this looks like I messed up with Java versions or path information. But that's not the case (as far as I'm aware):
> library(rJava)
> .jinit()
> .jcall("java/lang/System", "S", "getProperty", "java.version")
[1] "1.8.0_151"
> .jcall("java/lang/System", "S", "getProperty", "java.home")
[1] "C:\\Program Files\\Java\\jre1.8.0_151"
> .jcall("java/lang/System", "S", "getProperty", "sun.arch.data.model")
[1] "64"
> .jcall("java/lang/System", "S", "getProperty", "os.arch")
[1] "amd64"
This shows that os architecture and Java architecture match (R is 64-bit as well), that java.home is set correctly and also that rJava works nicely on my machine.
Now I'm not sure I understand the error message correctly but it seems that R is trying to load the 32-bit version of rJava during installation which fails. I tested this by changing java home to a 32-bit installation on my machine:
> options(java.home="C:/Program Files (x86)/Java/jre1.8.0_151") #32-bit version
> library(rJava)
Error: package or namespace load failed for ‘rJava’:
.onLoad failed in loadNamespace() for 'rJava', details:
call: inDL(x, as.logical(local), as.logical(now), ...)
error: unable to load shared object 'C:/Users/binis/Documents/R/win-library/3.4/rJava/libs/x64/rJava.dll':
LoadLibrary failure: %1 is not a valid Win32 application.
The error is the same which supports my assumption. However, I do not understand why R would try to use a different Java version during installtion or how I could stop that. I already tested if INSTALL_opts = c("--no-multiarch", "--no-test-load"), type="source" will do anything but the error remains the same...
After I spent some more time on google/stackoverflow, I found that the syntax of install_github is apparently slightly different from install.packages. Instead of ´INSTALL_opts´, options are invoked with ´args´. The follwing command, therefore, installs the example package without "complaints":
devtools::install_github("ropensci/tabulizer",
args = c("--no-multiarch", "--no-test-load"))
I leave this here in case others run into the same issue.

coreNLP & rJava installation issue from gitbub in R

fellow stackoverflowers!
I was trying to install coreNLP from github as there is a bug in the coreNLP package that comes with R.
Now while installing the coreNLP from github using below
To download the R library and corresponding CoreNLP java library, run the following in R:
devtools::install_github("statsmaths/coreNLP")
coreNLP::downloadCoreNLP()
I got an error
installing source package 'coreNLP' ...
** R
** data
* moving datasets to lazyload DB
** 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 'coreNLP':
.onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: No CurrentVersion entry in Software/JavaSoft registry! Try re-installing Java and make sure R and Java have matching architectures.
Error: loading failed
Execution halted
* arch - x64
ERROR: loading failed for 'i386'
removing 'C:/Users/animshru/Documents/R/win-library/3.4/coreNLP'
Installation failed: Command failed (1)
After looking at many suggestions what I understood was
i) I was missing the class file path for Java Home and added the same and tried installing coreNLP again.
Sys.setenv(JAVA_HOME='C:/Program Files/Java/jre1.8.0_121')
devtools::install_github("statsmaths/coreNLP")
This time the error generated relates to the package/library rJava as seen below
Downloading GitHub repo statsmaths/coreNLP#master
from URL https://api.github.com/repos/statsmaths/coreNLP/zipball/master
Installing coreNLP
"C:/PROGRA~1/R/R-34~1.1/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \
"C:/Users/XYZ/AppData/Local/Temp/RtmpieUxG6/devtools3c0456877ca/statsmaths-coreNLP-caee22e" \
--library="C:/Users/XYZ/Documents/R/win-library/3.4" --install-tests
installing source package 'coreNLP' ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
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/XYZ/Documents/R/win-library/3.4/rJava/libs/x64/rJava.dll':
LoadLibrary failure: The specified module could not be found.
ERROR: lazy loading failed for package 'coreNLP'
* removing 'C:/Users/XYZ/Documents/R/win-library/3.4/coreNLP'
Installation failed: Command failed (1)
I have installed the rJava package successfully and able to access the library for the same. Now I need to understand why I am getting this error of access issue to a rjava.dll file inside the package rJava.?
Has anyone encountered the same problem already??
I have double and triple checked the java version is 64bit same as the R.
Any hints folks??
Thanks

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"))

Resources