Using R without X11 [duplicate] - r

I'm running R 2.9 on a large EC2 Ubuntu instance, loaded with RAM, but without a terminal. When I load a library that has display dependencies, such as the sqldf package, I receive the following error:
library(sqldf)
...
Loading required package: tcltk
Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display "localhost:11.0"
Error : .onLoad failed in 'loadNamespace' for 'tcltk'
Error: package 'tcltk' could not be loaded
This seems to be a general problem, and I'm wondering how others have solved it. Installing an X11 server is not a desirable solution.

Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:
xvfb xauth xfonts-base
After installing these you can use the xvfb-run command. If you start R via e.g.
xvfb-run R --no-save
you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.
The same trick is useful for web servers.

Dirk's suggestion indeed works well, if you have control over the server & can run xvfb.
If not, read on...
in newer versions of R (>= 2.10 & maybe earlier), this is no longer an error, it's a warning:
> library(tcltk)
Loading Tcl/Tk interface ... done
Warning message:
In fun(libname, pkgname) : no DISPLAY variable so Tk is not available
You can now suppress this warning, and the subsequent package loading message via:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
Often you will see this message due to loading a package like qvalue which depends on tcltk; if you're after silent operation, you should silently load tcltk first, then the package of interest:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
> library(qvalue)
Mark
resurrected due to: http://dev.list.galaxyproject.org/wrapping-qvalue-in-Galaxy-td4655164.html

Related

R: install uroot package in ubuntu

I am trying to install the forecast package which depends on uroot, which apparently have been written to require a GPU?
install.packages("uroot") yields the following error. Has anyone found this issue and may suggest a work around? I am using ubuntu 16.04.
I have the file in question located here: /usr/local/cuda-8.0/ and I added to my path export PATH=/usr/local/cuda-8.0/:$PATH
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/home/rstudio2/R/x86_64-pc-linux-gnu-library/3.2/uroot/libs/uroot.so':
libcudart.so.8.0: cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/rstudio2/R/x86_64-pc-linux-gnu-library/3.2/uroot’
Warning in install.packages :
installation of package ‘uroot’ had non-zero exit status
Just in case this is useful for someone, I stumbled with the same problem trying to install "imputeTS" with R version 3.5.1 on Fedora 27 with CUDA 10.0 correctly installed an setted in PATH.
for me it just happened that I was running install.package("imputeTS") (which depends on forecast) in a R console as root, installing the packages to the user home solved the problem. It's seems that the libraries are searched in different places according to the user running the script, it's important to note that.
I just migrated to Linux. On an Ubuntu 18.04 setup, using install.packages with dependencies set to TRUE succeeded with no complaints. (No GPU on mu box.)
install.packages("forecast", dep=TRUE)
# there are quite a few dependencies and you happened to be missing one
packageDescription()
#-----------includes this line----------
Imports: colorspace, fracdiff, ggplot2 (>= 2.2.1), graphics, lmtest,
magrittr, nnet, parallel, Rcpp (>= 0.11.0), stats,
timeDate, tseries, urca, uroot, zoo
You can try to modify file "/etc/rstudio/rserver.conf", add "LD_LIBRARY_PATH" env, like:
rsession-ld-library-path=/usr/local/cuda/lib64
Actually, When you open session of "RStudio Server" from browser, the session does't get env from the ".bashrc".

installing rgl in amazon web services [duplicate]

I'm running R 2.9 on a large EC2 Ubuntu instance, loaded with RAM, but without a terminal. When I load a library that has display dependencies, such as the sqldf package, I receive the following error:
library(sqldf)
...
Loading required package: tcltk
Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display "localhost:11.0"
Error : .onLoad failed in 'loadNamespace' for 'tcltk'
Error: package 'tcltk' could not be loaded
This seems to be a general problem, and I'm wondering how others have solved it. Installing an X11 server is not a desirable solution.
Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:
xvfb xauth xfonts-base
After installing these you can use the xvfb-run command. If you start R via e.g.
xvfb-run R --no-save
you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.
The same trick is useful for web servers.
Dirk's suggestion indeed works well, if you have control over the server & can run xvfb.
If not, read on...
in newer versions of R (>= 2.10 & maybe earlier), this is no longer an error, it's a warning:
> library(tcltk)
Loading Tcl/Tk interface ... done
Warning message:
In fun(libname, pkgname) : no DISPLAY variable so Tk is not available
You can now suppress this warning, and the subsequent package loading message via:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
Often you will see this message due to loading a package like qvalue which depends on tcltk; if you're after silent operation, you should silently load tcltk first, then the package of interest:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
> library(qvalue)
Mark
resurrected due to: http://dev.list.galaxyproject.org/wrapping-qvalue-in-Galaxy-td4655164.html

Installing & using the asbio package under OS X

I'm a TA in a statistics class, and the students are supposed to use the "asbio" package in r for multiple comparisons. Some of those who have OSX are complaining that asbio will not load. I cannot reproduce the error on my own mac.
Here are the errors one of the students is seeing:
>library(asbio)
Loading required package: tcltk
Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package ‘tcltk’ could not be loaded
> install.packages("tcltk")
Warning in install.packages :
package ‘tcltk’ is not available (for R version 3.1.1)
Here are a few things students have tried:
install tcltk2: "It works now, but I still get errors" (Sorry, I know that's a confusing answer, but it's what I have)
install xquartz: "Now it works."
I suspect that xquartz is the right answer here, but if anybody could explain what's going on and confirm, that would be awesome.
(And why the ^& would a numerical statistics package need tcl/tk anyway???)
tcl/tk needs an X11 environment to work in for graphical output and Apple no longer ships an X11 environment with their operating system. XQuartz fills that gap, but is a separate install. Said install makes the X11 libraries available (look at the missing libraries in your errors) and those libraries—in turn—make graphical operations with tcl/tk possible.
the absio package has functions that let you do animation (like anim.ci) which rely on the graphics capabilities of tcl/tk.
A student in the class posted the following instructions:
1) Install xquartz. You don't need to click it ever again after installing it.
2) Restart computer.
3) Open Rstudio (or whatever R). Run library(tcltk). Don't use require or install.packages for it. Computer should now open up xquartz on its own.
4) Run install.packages("asbio")
5) library(asbio)
6) You should be able to run pairw.anova.
(I'm still waiting to see if the student wants credit by name here, but in any case, I'm thankful to them.)

Problems when trying to load a package in R due to rJava

When I type require(xlsx) in order to load the package xlsx in R, the following messages is shown:
> require(xlsx)
Loading required package: xlsx
Loading required package: xlsxjars
Loading required package: rJava
Error : .onLoad failed in loadNamespace() for 'rJava', details:
call: fun(libname, pkgname)
error: JAVA_HOME cannot be determined from the Registry
Failed with error: ‘package ‘rJava’ could not be loaded’
I've also tried to load the rJava package manually but got this error message:
require(rJava)
Loading required package: rJava
Error : .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.
Do you have any suggestion on how to solve the problem?
The reason is probably linked to the fact you are using a 64-bit OS and R version but do not have Java installed with the same architecture.
What you have to do is to download Java 64-bit from this page: https://www.java.com/en/download/manual.jsp
After that just try to reload the xlsx package. You shouldn't need to re-start R or if it does not work restart once.
Its because either one of the Java versions(32 bit/64 bit) is missing from your computer. Try installing both the Jdks and run the code.
After installing the Jdks open R and type the code
system("java -version")
This will give you the version of Jdk installed. Then try loading the rJava package. This worked for me.
I had a similar problem what worked for me was to set JAVA_HOME. I tired it first in R:
Sys.setenv(JAVA_HOME = "C:/Program Files/Java/jdk1.8.0_101/")
And when it actually worked I set it in
System Properties -> Advanced -> Environment Variables
by adding a new System variable. I then restarted R/RStudio and everything worked.
I had a similar issue. It is caused due the dependent package 'rJava'. This problem can be overcome by re-directing the R to use a different JAVA_HOME.
if(Sys.getenv("JAVA_HOME")!=""){
Sys.setenv(JAVA_HOME="")
}
library(rJava)
This worked for me.
If you have this error in RStudio, use Lauren's environmental code above and change your R version to the 32 bit version in Tools, Global Options. There should be both 32bit and 64bit R options if you have a newer version. This will require a restart of R, and limit your memory options. Installing the 64 bit version of the jre won't be required though.
An alternative package that you can use is readxl. This package doesn't require external dependencies.
For reading/writing excel files, you can use :
readxl package for reading and writexl package for writing
openxlsx package for reading and writing
With xlsx and XLConnect (which use rjava) you will face memory errors if you have large files
Answer in link resolved my issue.
Before resolution, I tried by adding JAVA_HOME to windows environments. It resolved this error but created another issue. The solution in above link resolves this issue without creating additional issues.
If you have this issue with macOS, there is no easy way here: ( Especially, when you want to use R3.4. I have been there already.
R 3.4, rJava, macOS and even more mess
For R3.3 it's a little bit easier (R3.3 was compiled using different compiler).
R, Java, rJava and macOS adventures
For me, I simply needed to make sure the Java was 64-bit (to match R).
Here's how I downloaded and installed 64-bit Java:
Go to: https://www.java.com/en/download/manual.jsp
Click on "Windows Offline (64-bit)"
Install it (you may need to find the file that downloaded and double click it, or it may automatically install)
Close and reopen your R/RStudio session
Everything will work as expected!

How to run R on a server without X11, and avoid broken dependencies

I'm running R 2.9 on a large EC2 Ubuntu instance, loaded with RAM, but without a terminal. When I load a library that has display dependencies, such as the sqldf package, I receive the following error:
library(sqldf)
...
Loading required package: tcltk
Loading Tcl/Tk interface ... Error in fun(...) : couldn't connect to display "localhost:11.0"
Error : .onLoad failed in 'loadNamespace' for 'tcltk'
Error: package 'tcltk' could not be loaded
This seems to be a general problem, and I'm wondering how others have solved it. Installing an X11 server is not a desirable solution.
Use the virtual framebuffer X11 server -- we do the same to build packages requiring X11 for R builds in headless chroots. Taking e.g. pars of the Build-Depends from rggobi:
xvfb xauth xfonts-base
After installing these you can use the xvfb-run command. If you start R via e.g.
xvfb-run R --no-save
you should now be able to use routines and commands requiring X11 as e.g. some of the plotting devices, or the tcl/tk initialization which also insists on having X11.
The same trick is useful for web servers.
Dirk's suggestion indeed works well, if you have control over the server & can run xvfb.
If not, read on...
in newer versions of R (>= 2.10 & maybe earlier), this is no longer an error, it's a warning:
> library(tcltk)
Loading Tcl/Tk interface ... done
Warning message:
In fun(libname, pkgname) : no DISPLAY variable so Tk is not available
You can now suppress this warning, and the subsequent package loading message via:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
Often you will see this message due to loading a package like qvalue which depends on tcltk; if you're after silent operation, you should silently load tcltk first, then the package of interest:
> suppressPackageStartupMessages(suppressWarnings(library(tcltk)))
> library(qvalue)
Mark
resurrected due to: http://dev.list.galaxyproject.org/wrapping-qvalue-in-Galaxy-td4655164.html

Resources