美文网首页
WLS 搭建数据科学环境之Jupyter运行R

WLS 搭建数据科学环境之Jupyter运行R

作者: scienceboy | 来源:发表于2019-07-11 00:46 被阅读0次

    Jupyter搭建运行R

    Ubuntu 在WIN10系统中的使用,双系统的实现,极大拓展了WIN10的应用范围。不过在实际使用过程中,WIN10/Ubuntu 这种双系统模式还是不如MacOS/UNIX(Linux)的自然一体。WIN10/Ubuntu关系相对对立,经常路径不同意,软件重复在不同平台安装,互通性不足。这其中Python和R在交互使用中可能会存在这样的问题。Anaconda是Python很好的集成开发环境(Integrated Development Environment, IDE),其中jupyter notebook可以很好管理、可视化Python运行代码和结果。RStudio自然是R语言必备IDE。

    Linux下推荐搭配miniconda/jupyter python环境,WIN10下一般安装R/RStudio。某种条件下,如何解决想在jupypter运行R代码呢?

    1. miniconda/juypter安装

    NOTE: Ubuntu 18.04 LTS

     #下载miniconda3  
     wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/miniconda/Miniconda3-latest-Linux-x86_64.sh
    
     #安装
     bash Miniconda3-latest-Linux-x86_64.sh -p /opt/biosoft/miniconda3
     ​
     #配置环境变量
     echo "export PATH=/opt/biosoft/miniconda3/bin:$PATH" >> ~/.bashrc # or ~/.zshrc  
     source ~/.bashrc
    

    配置TUNA镜像

     conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
     conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
     conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda
     conda config --set show_channel_urls yes
    

    jupyter安装

    #使用conda安装
     conda install -n base jupyter
     codna install -n base jupyterlab
     ​
     #或者使用pip安装
     pip install jupyterlab
     pip install jupyter</pre>
    

    2. R安装

    安装最新R 3.6.0

     #添加官网R版本路径
     vi /etc/apt/sources.list
     #加入下面链接
     deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/
     ​
     sudo apt-get update
     sudo apt-get install r-base
     sudo apt-get install r-base-dev
    

    3. R加载到jupyter中

    安装依赖包

    # R
     install.packages('devtools')
     devtools::install_github('IRKernel/IRkernel')
     IRkernel::installspec(name = 'ir', displayname = 'R')
    

    运行

     jupyter lab --allow-root
     #可以看到R 图标
    
    Snipaste_2019-07-11_00-19-08.png

    notebook中新建R命令文档

    jupter notebook --allow-root
    
    Snipaste_2019-07-11_00-21-29.png

    4. Jupyter R命令文档

    一般文档后缀还是.ipynb。但代码格式完全一样,可以自然快速的从RStudio开发环境中过渡。至此,Jupyter可以很好的统一管理Python和R。


    Snipaste_2019-07-11_00-28-08.png

    相关文章

      网友评论

          本文标题:WLS 搭建数据科学环境之Jupyter运行R

          本文链接:https://www.haomeiwen.com/subject/dyelkctx.html