美文网首页
在jupyter中使用R

在jupyter中使用R

作者: ayunga | 来源:发表于2021-12-10 20:29 被阅读0次

    1.conda搭建新环境

    装R、Python、Jupyter

    $ conda create -n R4.0
    $ conda activate R4.0
    $ conda install r-base=4.0.5
    $ conda install python=3.9.7
    $ conda install jupyter
    

    2.配置Jupyter

    因为之前在conda(base)下安装过juputer,虽然在新环境下,但这次也不用再去配置(我不理解为啥)。
    但不用conda再在新环境 install 一个 jupyter的话,后续步骤就会报这种错( 我不理解为啥x2)。

    > library('IRkernel')                                                                                                                                                                                                                                       
    > IRkernel::installspec(user = FALSE)                                                                                                                                                                                                                       
    Error in IRkernel::installspec(user = FALSE) :                                                                                                                                                                                                              
      jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.                                                                                                                                                               
    In addition: Warning message:                                                                                                                                                                                                                               
    In system2("jupyter", c("kernelspec", "--version"), FALSE, FALSE) :                                                                                                                                                                                         
      error in running command 
    

    但是我认为,如果是第一次安装jupyter的话,肯定是需要配置的,此处省去配置的步骤(毕竟也不用配置了)。

    3.安装R包

    在 R console 中输入

    > install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'uuid', 'digest'))
    

    4.安装R包 devtools

    $ conda install r-devtools  ##这个包 install.packages没装明白
    

    5.安装 IRkernel 包

    先尝试在 R console 中输入

    > devtools::install_github('IRkernel/IRkernel') 
    Downloading GitHub repo IRkernel/IRkernel@HEAD                                                                                                                                                                                                              
    Error in utils::download.file(url, path, method = method, quiet = quiet,  :                                                                                                                                                                                 
      cannot open URL 'https://api.github.com/repos/IRkernel/IRkernel/tarball/HEAD'
    

    装不了,换个姿势

    > install.packages('IRkernel')
    

    6.使 R 在 Jupyter Notebook 中可以被探测到

    在 R console 中输入

    ## To install system-wide, set user to False in the installspec command
    > IRkernel::installspec(user = FALSE)
    [Errno 13] Permission denied: '/usr/local/share/jupyter'
    Perhaps you want to install with `sudo` or `--user`?
    ## Ok, Ok, It seems doesn`t  work.
    
    ## Using following command to install the kernel for the current user
    > IRkernel::installspec()
    [InstallKernelSpec] Installed kernelspec ir in /home/ayunga/.local/share/jupyter/kernels/ir
    

    至此,安装完成。

    7.测试一下是否安装成功

    再次打开 jupyter notebook,在右侧新建的下拉选择里面出现 R,就代表安装成功了。


    至此,Jupyter Notebook 里已正确添加 R 核。
    测试一下



    好用的!

    相关文章

      网友评论

          本文标题:在jupyter中使用R

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