213 words
1 minutes
Jupyter中使用R

简介#

  • Rstudio固然不错,但不可能只用R吧
  • 虽然Rstudio也支持Python了,但正经人谁会用Rstudio写Python呢
  • 习惯以后还是随手点开VScode然后新建.ipynb切R内核写代码爽哈,一点都不比RMarkdown差

安装#

Jupyter#

  • JupyterLab(Web版IDE)
# 安装
pip install jupyterlab
# 打开
jupyter lab
  • Jupyter Notebook(纯Notebook)
# 安装
pip install notebook
# 打开
jupyter notebook

R kernel#

  • 打开R终端,输入以下代码即可
install.packages('IRkernel')
IRkernel::installspec()  
jupyter labextension install @techrah/text-shortcuts  

快捷键#

  • 个人设置的快捷键
[
    {
        "key": "ctrl+cmd+[Minus]",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'r'|'Rmd'|'ipynb'",
        "args": {
            "snippet": " <- "
        }
    },
    {
        "key": "ctrl+cmd+[Equal]",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'r'|'Rmd'|'ipynb'",
        "args": {
            "snippet": " %>% "
        }
    },
    {
        "key": "ctrl+cmd+[IntlYen]",
        "command": "editor.action.insertSnippet",
        "when": "editorTextFocus && editorLangId == 'r'|'Rmd'|'ipynb'",
        "args": {
            "snippet": " |> "
        }
    },
    {
        "key": "ctrl+cmd+5",
        "command": "type",
        "args": {
            "text": " %in% "
        }
]