1 基础知识
1.1 RStudio的介绍
RStudio是R编程语言集成开发环境(IDE)
1.2 RStudio的特点
RStudio支持定制工作台,包含R所需的所有工具(控制台、源代码、绘图、工作区、帮助、历史记录等)
RStudio支持语法高亮显示
RStudio支持直接从源代码编辑器执行代码
RStudio支持Windows、MAC和Linux平台
Rstudio支持服务器端运行,允许多个用户通过Web浏览器访问IDE环境(RStudio Server)
2 最佳实践
2.1 环境配置
2.1.1 系统环境配置
OS = CentOS 8.x x86_64
Host Name = rstudio.cmdschool.org
IP Address = 10.168.0.68
2.1.2 关闭SELinux
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config setenforce 0
2.2 安装R
2.2.1 下载指定版本的安装包
export R_VERSION=4.1.2 curl -O https://cdn.rstudio.com/r/centos-8/pkgs/R-${R_VERSION}-1-1.x86_64.rpm
2.2.2 安装R包
yum install R-${R_VERSION}-1-1.x86_64.rpm
2.2.3 设置环境变量
export R_VERSION=4.1.2 ln -s /opt/R/${R_VERSION}/bin/R /usr/local/bin/R ln -s /opt/R/${R_VERSION}/bin/Rscript /usr/local/bin/Rscript
设置完毕后,可使用如下命令确认设置,
R --version
2.4 安装R Server
2.4.1 下载R Server包
wget https://download2.rstudio.org/server/centos8/x86_64/rstudio-server-rhel-2021.09.1-372-x86_64.rpm
2.4.2 安装R Server包
yum install rstudio-server-rhel-2021.09.1-372-x86_64.rpm
2.4.3 启动服务器并设置自启动
systemctl start rstudio-server.service systemctl restart rstudio-server.service systemctl status rstudio-server.service systemctl enable rstudio-server.service
服务启动后,可使用如下命令查确认服务运行,
netstat -antp | grep rserver
可见如下显示,
tcp 0 0 0.0.0.0:8787 0.0.0.0:* LISTEN 406/rserver
2.4.4 开放防火墙端口
firewall-cmd --permanent --add-port 8787/tcp firewall-cmd --reload firewall-cmd --list-all
2.4.5 设置用户
useradd user01 echo userpwd | passwd --stdin user01
2.4.6 测试服务
http://10.168.0.68:8787
user name: user01
user password: userpwd
2.5 环境变量定义
2.5.1 查看环境变量
Sys.getenv()
登录之后可在IDE的“Console”里面执行,可见如下显示,
> Sys.getenv() CLICOLOR_FORCE 1 DISPLAY :0 EDITOR vi GIT_ASKPASS rpostback-askpass HOME /home/user01 LANG en_US.UTF-8 LD_LIBRARY_PATH /opt/R/4.1.2/lib/R/lib:/lib:/usr/local/lib LN_S ln -s LOGNAME user01 MAKE make MPLENGINE tkAgg NLSPATH /usr/dt/lib/nls/msg/%L/%N.cat PAGER /usr/bin/less PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/usr/lib/rstudio-server/bin/postback R_BROWSER xdg-open R_BZIPCMD /usr/bin/bzip2 R_DOC_DIR /opt/R/4.1.2/lib/R/doc R_GZIPCMD /usr/bin/gzip R_HOME /opt/R/4.1.2/lib/R R_INCLUDE_DIR /opt/R/4.1.2/lib/R/include R_LIBS_SITE R_LIBS_USER ~/R/x86_64-pc-linux-gnu-library/4.1 R_PAPERSIZE letter R_PDFVIEWER /usr/bin/open R_PLATFORM x86_64-pc-linux-gnu R_PRINTCMD /usr/bin/lpr R_RD4PDF times,hyper R_SESSION_TMPDIR /tmp/RtmpLjT9Kx R_SHARE_DIR /opt/R/4.1.2/lib/R/share R_STRIP_SHARED_LIB strip --strip-unneeded R_STRIP_STATIC_LIB strip --strip-debug R_SYSTEM_ABI linux,gcc,gxx,gfortran,gfortran R_TEXI2DVICMD /usr/bin/texi2dvi R_UNZIPCMD /usr/bin/unzip R_ZIPCMD /usr/bin/zip RMARKDOWN_MATHJAX_PATH /usr/lib/rstudio-server/resources/mathjax-27 RS_RPOSTBACK_PATH /usr/lib/rstudio-server/bin/rpostback RS_SESSION_TMP_DIR /var/run/rstudio-server/rstudio-rsession RSTUDIO 1 RSTUDIO_CONSOLE_COLOR 256 RSTUDIO_CONSOLE_WIDTH 96 RSTUDIO_HTTP_REFERER http://rstudio.cmdschool.org:8787/ RSTUDIO_PANDOC /usr/lib/rstudio-server/bin/pandoc RSTUDIO_PROGRAM_MODE server RSTUDIO_R_MODULE RSTUDIO_R_PRELAUNCH_SCRIPT RSTUDIO_R_REPO RSTUDIO_R_VERSION_LABEL RSTUDIO_SESSION_STREAM user01-d RSTUDIO_USER_IDENTITY user01 RSTUDIO_USER_IDENTITY_DISPLAY user01 RSTUDIO_WINUTILS bin/winutils SED /usr/bin/sed SSH_ASKPASS rpostback-askpass TAR /usr/bin/gtar TERM xterm-256color USER user01 XFILESEARCHPATH /usr/dt/app-defaults/%L/Dt
如果需要修改“R_HOM”和“LD_LIBRARY_PATH”的环境变量定义,请使用如下命令编辑配置文件,
vim /etc/rstudio/rserver.conf
加入如下配置,
# Server Configuration File rsession-which-r=/opt/R/4.1.2/lib/R rsession-ld-library-path=/usr/java/jdk1.8.0_121/lib:/usr/java/jdk1.8.0_121/jre/lib
以上参数的意义,
“rsession-which-r”声明R的家目录位置(适用于安装多个版本的R中指定一个特定版本)
“rsession-ld-library-path”声明R需要调用的其他库文件的位置(范例声明Java库文件的位置)
====================
官方站点
————-
https://github.com/rstudio/rstudio
https://www.rstudio.com/
产品列表
————
https://www.rstudio.com/products/rstudio/#rstudio-server
https://support.rstudio.com/hc/en-us/articles/200552306-Getting-Started
软件的下载
————-
https://www.rstudio.com/products/rstudio/download-server/
安装R
—————
https://docs.rstudio.com/resources/install-r/
RStudio配置文件
—————-
https://docs.rstudio.com/ide/server-pro/r_sessions/r_executable_and_libraries.html
https://github.com/jjallaire/rsp-admin-guide/blob/master/05-r-sessions.Rmd
没有评论