5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

VSCodeでRMarkdownを使う

Posted at

よくわからないけれど動いたという備忘録です.
rmarkdown や knitr などの package のインストールが必要です.
使っているOSはWindowsです.

VSCode での R のセットアップ

英語ですが VSCode での R のセットアップは
https://medium.com/analytics-vidhya/a-fresh-start-for-r-in-vscode-ec61ed108cf6
が参考になります.

vscode-r の R Session Watcher をオンにする

その後,VSCode の settings.json に

settings.json
"r.sessionWatcher": true

を追加し, R Session Watcher を使えるようにします.

keybinding の設定

https://github.com/Ikuyadeu/vscode-R#creating-keybindings-for-r-commands
に書いてある通りに VSCode の keybindings.json に

keybindings.json
    {
        "description": "knit to html",
        "key": "ctrl+i",
        "command": "r.runCommandWithEditorPath",
        "when": "editorTextFocus",
        "args": "rmarkdown::render(\"$$\", output_format = rmarkdown::html_document(), output_dir = \".\", clean = TRUE)"
    }

を追加します.
これで rmd ファイルを開いているときに ctrl+i で,VSCode で開いているディレクトリ直下へ html として出力できます.

Preview

ちなみに
https://github.com/Ikuyadeu/vscode-R/issues/103#issuecomment-567054476
にあるとおりに R のコンソールで

rmarkdown::run("path to rmd file")

を実行すると preview を見ることができます.

##参考
https://medium.com/analytics-vidhya/a-fresh-start-for-r-in-vscode-ec61ed108cf6
https://github.com/Ikuyadeu/vscode-R#creating-keybindings-for-r-commands
https://github.com/Ikuyadeu/vscode-R/issues/103#issuecomment-567054476

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?