conda 创建R环境:
conda create -n lry_R4.2.2
conda activate lry_R4.2.2
conda install -c conda-forge r-base=4.2.2
安装完后,输入R,就可以运行R了。退出输入q();在该R环境中,就可以安装相应的R包了。可以在该R环境下安装对应的R包。或者用conda 安装,如安装包
ggplot2
conda install r-ggplot2#R包通常需要以r-开头
在 conda 环境中安装 R 包管理工具 conda-forge:
conda install -c conda-forge r-irkernel
这个命令会安装 IRkernel 包,这是一个 R 语言的 Jupyter 内核,可以在 Jupyter Notebook 或 JupyterLab 中运行 R 代码。
安装jupyter notebook.
pip install jupyter notebook
安装完,启动,jupyter notebook但是会提示如下信息:
Command ‘jupyter’ not found, but can be installed with:
sudo snap install jupyter # version 1.0.0, or
sudo apt install jupyter-core # version 4.6.3-3
See ‘snap info jupyter’ for additional versions.
通过这个命令安装后,在启动。
sudo snap install jupyter
启动之后,就可以用了python,但R环境还不成功。做了下面的还是不行。
install.packages(“devtools”)
选择区域,中国随便一个地方,我选25;
安装不成功,报错:其中ragg安装也是同样错误。
fatal error: ft2build.h: No such file or directory
又安装下列
sudo apt-get install libgtk-3-dev
还是报错,缺少libtiff4;又安装如下
sudo apt-get install libtiff-dev
还是出错:
Configuration failed to find one of freetype2 libpng libtiff-4 libjpeg. Try installing:
* deb: libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev (Debian, Ubuntu, etc)
* rpm: freetype-devel libpng-devel libtiff-devel libjpeg-devel (Fedora, CentOS, RHEL)
* csw: libfreetype_dev libpng16_dev libtiff_dev libjpeg_dev (Solaris)
If freetype2 libpng libtiff-4 libjpeg is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a freetype2 libpng libtiff-4 libjpeg.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
那继续安装如下依赖项目:
sudo apt-get install -y libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev
还是不行。继续安装
conda install -c conda-forge pkg-config
ragg终于安装成功。在安装devtools
终于安装成功:
利用镜像工具从github网站下载安装R kernel:
devtools::install_github('IRkernel/IRkernel')
在R中注册激活R kernel
IRkernel::installspec() # to register the kernel in the current R installation
但不成功:
> IRkernel::installspec()
Traceback (most recent call last):
File "/snap/jupyter/6/bin/jupyter-kernelspec", line 10, in <module>
sys.exit(KernelSpecApp.launch_instance())
File "/snap/jupyter/6/lib/python3.7/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/snap/jupyter/6/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 273, in start
return self.subapp.start()
File "/snap/jupyter/6/lib/python3.7/site-packages/jupyter_client/kernelspecapp.py", line 143, in start
replace=self.replace,
File "/snap/jupyter/6/lib/python3.7/site-packages/jupyter_client/kernelspec.py", line 346, in install_kernel_spec
shutil.copytree(source_dir, destination)
File "/snap/jupyter/6/lib/python3.7/shutil.py", line 315, in copytree
names = os.listdir(src)
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/Rtmp7kyPFR/filea6b207c3f2c/kernelspec'
那就不用这种把,安装Rstudio server吧;
按照此过程安装:
https://www.cnblogs.com/liujiaxin2018/p/16215241.html
注意:我需要的是我已经安装R2.2.2的环境,那就需要进行修改,先产看R的路径
R.home()
[1] "/home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib/R"
将R路径写入Rstudio的配置文件,输入如下内容。
sudo vim /etc/rstudio/rserver.conf
# Server Configuration File
rsession-which-r=/home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib/R
通过rstudio-server stop停止服务。配置好,之后,在重新启动。rstudio-server restart
rstudio-server status
查看状态,是否active (running)
之前的,版本就替换成现在的版本了;这样就安装成功了。
但导入安装的包会出错
错误: package or namespace load failed for ‘destiny’ in dyn.load(file, DLLpath = DLLpath, ...):
无法载入共享目标对象‘/home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib/R/library/Rcpp/libs/Rcpp.so’::
/lib/x86_64-linux-gnu/libstdc++.so.6: version `GLIBCXX_3.4.29' not found (required by /home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib/R/library/Rcpp/libs/Rcpp.so)
解决方法如下:
conda install libgcc
export LD_LIBRARY_PATH=/home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib:$LD_LIBRARY_PATH
cd /home/jx-vmlab/miniconda3/envs/lry_R4.2.2/lib
ln -s libstdc++.so.6.0.32 libstdc++.so.6
you can add export LD_LIBRARY_PATH=/path/to/anaconda/envs/myenv/lib:$LD_LIBRARY_PATH to ~/.bashrc file.
若rstudio-server里面还不行:
参考以下一定行了。一定设置之后,需要重启rstudio-server;
我参考了,这个就搞定了
https://blog.csdn.net/phdsky/article/details/84104769
搞定如下:搞了一天,生信让我痛不欲生,我将与你终老。
还可以参考,这个,解决问题,也是参考上面连接。
https://cloud.tencent.com/developer/article/1819222