I have installed r-integration via npm. I have placed my R script inside the node-server directory which is located at srv/nodeserver/. I have R installed in my machine.
> whereis R
R: /usr/bin/R /usr/lib/R /etc/R /usr/local/lib/R /usr/share/R /usr/share/man/man1/R.1.gz
The nodejs REST API code looks like below:
app.get('/getRresult',(req,res)=>{
let result = R.executeRScript(
'server.R',"circumference",{r:2});
console.log(result)
});
When I hit the RESTAPI url I get the following error:
Error: R not found, maybe not installed.
However R is installed because if I type R in the terminal R shell opens up. I tried exporting the path of usr/bin/R in ~/.bashrc. It still does not seem to work. I am confused which path will actually work or how to set the path for ubuntu PATH variable.
You needs to install R on your ubuntu.
Here are steps
#1 Install the dependencies necessary
to add a new repository over HTTPS:
$ sudo apt install dirmngr gnupg apt-transport-https ca-certificates software-properties-common
#2 Add the CRAN repository to your system sources’ list
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
$ sudo add-apt-repository 'deb https://cloud.r-project.org/bin/linux/ubuntu focal-cran40/'
#3 Install R
$ sudo apt install r-base
#4 Verify R version
R --version
Terminal Output
$ R --version
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
#5 Finally run simple example
test.js will call test.R by R.executeRScript()
It will return value into test.js then it will console.log()
file name save as test.js
const R = require('r-integration');
let result = R.executeRScript("./test.R");
console.log(result);
file name save as test.R
x <- 5
y <- 6
z <- 3
result <- max(x, y, z)
print(result)
Install r-integration library
npm install r-integration
Run it and see the Result
$ node test.js
[ 6 ]
References
R-integration - Node JS API
How to Install R on Ubuntu 20.04
Related
I am sure this is a trivial question, but I am trying to install multiple R versions in Linux. I am not using R studio server pro and am instead using the free R studio server. I followed this documentation to install R but got errors when I attempted to locate it. However, when I run a command to see what version of R is installed, there is no error.
R is installed!
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ /opt/R/4.1.3/bin/R --version
R version 4.1.3 (2022-03-10) -- "One Push-Up"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
https://www.gnu.org/licenses/.
Attempts
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ R
Command 'R' not found, but can be installed with:
sudo apt install r-base-core
(base) noah#noah-VirtualBox:/opt/R/4.1.3$ which R
(base) noah#noah-VirtualBox:/opt/R/4.1.3$
Steps to reproduce
export R_VERSION=4.1.3
curl -O https://cran.rstudio.com/src/base/R-4/R-${R_VERSION}.tar.gz
tar -xzvf R-${R_VERSION}.tar.gz
cd R-${R_VERSION}
# Build and install R
./configure \
--prefix=/opt/R/${R_VERSION} \
--enable-memory-profiling \
--enable-R-shlib \
--with-blas \
--with-lapack
make
sudo make install
# Verify R installation
/opt/R/${R_VERSION}/bin/R --version
# Create a symlink to R
sudo ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R
sudo ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
# Export path so Rstudio can find it
export RSTUDIO_WHICH_R='/opt/R/4.1.3/bin'
You are overcomplicating it. Just install in, say,
/opt/R/4.2.0/
/opt/R/4.1.2/
/opt/R/4.0.5/
and then either set the $PATH to the bin/ directory in the version you want, or call R directly. It is what pretty much exactly what many of us have done with two versions of R (i.e. R-release and R-devel):
$ R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$
$ /usr/lib/R/bin/R --version | head -1
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
$
$ /usr/local/lib/R-devel/bin/R --version | head -1
R Under development (unstable) (2022-05-24 r82398) -- "Unsuffered Consequences"
$
The first two are the same as that is my 'default' version. The third is my one alternate. And that is all there is to it.
If you add /usr/local/bin to your $PATH variable you would have been able to launch R, if it was not already present.
You could add it to .bashrc in your home directory
echo "export path=\"${PATH}:/usr/local/bin\"" |tee -a ~/.bashrc
Links for installing R from package, Ubuntu / Debian, RHEL 9, RHEL 8, RHEL/CentOS7
https://docs.posit.co/resources/install-r/
Also see
(Optional) Install multiple versions of R, on the same page.
I had a docker image that was building successfully for months. However, since Dec 17th I've run into the error shown in the Jenkins console output below. Nothing has changed in the dockerfile so it's clearly something to do with the underlying environment, I have a Jenkins server running on AWS EC2. The strange thing is all the other packages are installing fine without any reference to R_HOME, it's just the XML package install that's failing
I've tried explicitly setting R_HOME in the dockerfile as per this thread but no luck.
ENV R_HOME /usr/lib/R
Jenkins stage
stage ('Build docker image') {
steps {
dir ('DockerImage') {
sh 'docker-compose build'
}
}
}
Jenkins console output
Step 17/20 : RUN R -e "install.packages('XML')"
---> Running in cfc007e0ce94
[91mERROR: R_HOME ('/usr/lib/R') not found
Dockerfile
# Run executable JAR in Linux
FROM cardcorp/r-java
# Set R and jri PATH
ENV LD_LIBRARY_PATH "$LD_LIBRARY_PATH:/usr/bin/:/usr/lib/R/site-library/rJava/jri/"
# Install packages in R
RUN R -e "install.packages(c('data.table', 'Rcpp', 'zoo'))"
RUN R -e "install.packages('foreach')"
RUN R -e "install.packages('doParallel')"
RUN R -e "install.packages('signal')"
RUN R -e "install.packages('bitops')"
RUN R -e "install.packages('matlab')"
RUN R -e "install.packages('GENEAread')"
RUN R -e "install.packages('tuneR')"
RUN R -e "system('apt-key adv --keyserver keyserver.ubuntu.com --recv-keys ABC')"
RUN R -e "system('apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XYZ')"
RUN R -e "system('apt-get update && apt-get install -y gcc-8-base apt-transport-https')"
RUN R -e "system('apt-get install -y libxml2-dev')"
RUN R -e "install.packages('XML')"
Edit: Looking at the timestamp of when the issue started occurring, I spotted that there was a Debian release which coincides with my issue. I wonder if it's possible to specify the Debian version to use in the Docker file
In my case I tracked the issue down to test -x not working. The /usr/bin/R script uses that to check if the /usr/lib/R folder exists.
Searching for solutions to this sent me to various bug reports in Ubuntu but I managed to resolve the issue by upgrading docker version. My Docker host is Centos not Ubuntu like in most bug reports, however my container is based on Ubuntu.
Things worked again after upgrading Docker to the following packages:
Upgraded:
containerd.io-1.4.12-3.1.el8.x86_64
docker-ce-3:20.10.12-3.el8.x86_64
docker-ce-cli-1:20.10.12-3.el8.x86_64
docker-scan-plugin-0.12.0-3.el8.x86_64
Installed:
docker-ce-rootless-extras-20.10.12-3.el8.x86_64
fuse-overlayfs-1.7.1-1.module_el8.5.0+890+6b136101.x86_64
fuse3-3.2.1-12.el8.x86_64
fuse3-libs-3.2.1-12.el8.x86_64
libslirp-4.4.0-1.module_el8.5.0+890+6b136101.x86_64
slirp4netns-1.1.8-1.module_el8.5.0+890+6b136101.x86_64
See:
https://bugs.launchpad.net/cloud-images/+bug/1928218
https://bugs.launchpad.net/ubuntu/+source/libseccomp/+bug/1916485
I installed Rstudio using anaconda. I think the R was also installed alongside with it (but I read somewhere that Rstudio doesn't come with R: Tell me if I am wrong).
From terminal: which R shows :/home/simo/anaconda3/bin/R.
I tried that:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
sudo echo "deb http://cran.wustl.edu/bin/linux/ubuntu bionic-cran35/" | sudo tee -a /etc/apt/sources.list
sudo apt update
sudo apt upgrade
but doesn't upgrade the version of R (still R version 3.5.1 (2018-07-02) -- "Feather Spray")
At the first place I want to install: dashHtmlComponents, a dash library.
> install.packages("dashHtmlComponents")
Warning message:
package ‘dashHtmlComponents’ is not available (for R version 3.5.1)
>
But from the dash documentation I read that at least version 3.0.2 of R is required.
What is wrong?
It depends what OS you are on how you would go about doing that. The particular methods for Windows and MacOS are laid out on this page.
As far as if you have R (which it appears you do, but nonetheless), you can run install r-essentials --yes in the terminal (Mac) or Anaconda Prompt (PC). In Linux you can follow the steps here.
Once you do either of these, you should be able to use install.packages('dashHtmlComponents'). I am using R version 3.6.2 and it installs just fine.
On Ubuntu 18.04 LTS, while working R in JupyterNotebook (without Anaconda), the IRKernel is reading the R version 3.4. For using some packages like cowplot it is necessary to have at least version 3.5.
Basically, two steps should be taken:
Update R. These and that answers were a guideline.
Update IRKernel. The offical IRKernel instructions for Linux were useful.
Next, is described the complete procedure
1. Add Key to server
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
2. Add Entry to sources.list
echo 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/' | sudo tee -a /etc/apt/sources.list
Depending on the linux you're using you should change, for example, bionic by xenial or cosmic, check out https://cran.r-project.org/bin/linux/ubuntu/README.html
3. Update Programs
According to the instructions in the above link, we should do the following:
sudo apt-get update
sudo apt-get install r-base
sudo apt-get install r-base-dev
4. Update /.local/share/jupyter/kernels/ir
type R in the console and follow the next steps according to this link
# In the console
R
# Inside R
install.packages(c('repr', 'IRdisplay', 'IRkernel'), type = 'source')
getRversion() # to verify the new R version
IRKernel::installspec()
This should show the following message:
[InstallKernelSpec] Removing existing kernelspec in /home/user_name/.local/share/jupyter/kernels/ir
[InstallKernelSpec] Installed kernelspec ir in /home/user_name/.local/share/jupyter/kernels/ir
As a final remark, you should remove the older version of R, which you can find in ~/R/x86_64-pc-linux-gnu-library, where you will now have two directories with two different versions or R (remove the older one).
I'm working with R now for some month and I'm still a newbie.
I acutall working for a project to build up R RHadoop and Hadoop.
The sandbox + R + RStudio is already running and working.
I wanted to install R + RStudio also on the bigger cluster with several nodes for testing in cluster mode. But when I installed R, is saw, that a new version comes out, 3.2.2. On my sandbox, I'm still working with 3.2.1.
Version 3.2.2 seems to have some problem with my code, so I want to use 3.2.1, but I'm not able to install older version of R.
How can I install R-3.2.1-2.el6.x86_64 on the cluster as well?
I'm working on centos 6.
Regards,
suerte
I don't know if you found a solution at your problem, but here is how I install old R versions :
0) You should be sure to know which linux version you use
lsb_release -a
You should get something like (this is my result in example):
Distributor ID: Ubuntu
Description: Ubuntu 14.04
Release: 14.04
Codename: trusty
So now I know that my linux is a trusty.
1) After that you need to add a cran repository on your /etc/apt/sources.list
You can find cran address here : https://cran.r-project.org/mirrors.html
That give you access to older package. Choose one for your Linux !!
example :
deb https://cloud.r-project.org/bin/linux/ubuntu trusty/
2) You need to add the registry key to don't have certificate problem. I use this command but fell free to find another one on their website :
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys E084DAB9
gpg -a --export E084DAB9 | apt-key add -
3) Here is the tricky part :
1 --> do an apt-get update to have the new repository
2 --> choose your version in the cran and specify it. That should look like something like that :
apt-get -y install r-base-core=3.1.0-1trusty0 #For R
apt-get -y --force-yes install r-doc-html=3.1.0-1trusty0 #For doc
apt-get -y install r-base-dev=3.1.0-1trusty0 # for dev
etc ...
Just be careful, I had some problems when I tried to install r-base=.... and r-recommended= .... All the time, that had install the latest version.
For the cluster I don't know yet but I think a script should work.
Hope that helped.
Regards