jupyter notebook運行R語言代碼

0引言

我是一直以來是使用R語言來建模處理數據。python也只是入門,大大小小的模型都沒做過。用的編譯器是R語言基礎的編譯器Rstudiojupyter notebook。以後想使用python所以就想着都使用同一個編譯腳本。用啥呢?jupyter notebook,感覺還不錯還可以寫markdown。說做就做去網上找了教程。下面就分享記錄一下我今晚踩的坑,希望對大家有用。歡迎評論區留言,看到就回復。

1、度娘方案彙集

網上的攻略是先進行下面的代碼然後就OK了。

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
devtools::install_github('IRkernel/IRkernel')
# 只在當前用戶下安裝
IRkernel::installspec()
# 或者是在系統下安裝
IRkernel::installspec(user = FALSE)

但是到了我這裏確實各種報錯。

2、報錯信息彙總

下面是運行各條命令時的報錯彙總。

> install_github("IRkernel/IRkernel")
WARNING: Rtools is required to build R packages, but is not currently installed.
Please download and install Rtools custom from http://cran.r-project.org/bin/windows/Rtools/.
錯誤: Failed to install 'unknown package' from GitHub:
  schannel: failed to receive handshake, SSL/TLS connection failed
> install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
Warning: 無法在貯藏處https://mirrors.eliteu.cn/CRAN/src/contrib中讀寫索引:
  無法打開URL'https://mirrors.eliteu.cn/CRAN/src/contrib/PACKAGES'
Warning: 無法在貯藏處https://mirrors.eliteu.cn/CRAN/bin/windows/contrib/3.6中讀寫索引:
  無法打開URL'https://mirrors.eliteu.cn/CRAN/bin/windows/contrib/3.6/PACKAGES'
Warning message:
packages ‘repr’, ‘IRdisplay’, ‘evaluate’, ‘crayon’, ‘pbdZMQ’, ‘devtools’, ‘uuid’, ‘digest’ are not available (for R version 3.6.2) 
> devtools::install_github('IRkernel/IRkernel')
WARNING: Rtools is required to build R packages, but is not currently installed.
Please download and install Rtools custom from http://cran.r-project.org/bin/windows/Rtools/.
Downloading GitHub repo IRkernel/IRkernel@master
錯誤: Failed to install 'IRkernel' from GitHub:
  Git does not seem to be installed on your system.
> install.packages("devtools")
--- 在此連線階段時請選用CRAN的鏡子 ---
Warning: failed to download mirrors file (輸入中沒有多出的行); using local file 'D:/R-3.6.2/doc/CRAN_mirrors.csv'
Warning: 無法在貯藏處https://mirrors.eliteu.cn/CRAN/src/contrib中讀寫索引:
  無法打開URL'https://mirrors.eliteu.cn/CRAN/src/contrib/PACKAGES'
Warning: 無法在貯藏處https://mirrors.eliteu.cn/CRAN/bin/windows/contrib/3.6中讀寫索引:
  無法打開URL'https://mirrors.eliteu.cn/CRAN/bin/windows/contrib/3.6/PACKAGES'
Warning messages:
1: In download.file(url, destfile = f, quiet = TRUE) :
  downloaded length 0 != reported length 16791
2: package ‘devtools’ is not available (for R version 3.6.2) 

在這裏插入圖片描述

3、最終解決

最後經過探索知道只需要運行下面四行代碼即可。

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ', 'devtools', 'uuid', 'digest'))
install.packages("IRkernel")  # 這個包直接安裝即可,不用什麼路徑,其他的保持一致與上述鏈接
IRkernel::installspec()
IRkernel::installspec(user = FALSE)

4、代碼調試

下面貼出成功的畫面:
1、創建R語言代碼
在這裏插入圖片描述
2、代碼調試在這裏插入圖片描述

5、總結

具體使用體驗還是等用段時間再來評價,祝大家安裝成功。2020年04月14日 23:41

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章