Skip to content

Instantly share code, notes, and snippets.

@trilin6
Last active May 11, 2025 13:48
Show Gist options
  • Select an option

  • Save trilin6/767df72cc8bc32c5b9c73befe9bc78f5 to your computer and use it in GitHub Desktop.

Select an option

Save trilin6/767df72cc8bc32c5b9c73befe9bc78f5 to your computer and use it in GitHub Desktop.

Revisions

  1. trilin6 revised this gist May 11, 2025. No changes.
  2. trilin6 revised this gist May 11, 2025. No changes.
  3. trilin6 revised this gist May 11, 2025. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion guide.md
    Original file line number Diff line number Diff line change
    @@ -208,4 +208,27 @@ Here’s a fully organized workspace file with all settings!
    ### 🌐 Resources
    - [VSCode R Docs](https://code.visualstudio.com/docs/languages/r)
    - [REditorSupport Wiki](https://github.com/REditorSupport/vscode-R/wiki)
    - [Radian GitHub](https://github.com/randy3k/radian)
    - [Radian GitHub](https://github.com/randy3k/radian)
    -
    - ### Key Citations
    - [Official CRAN R Download Page](https://cloud.r-project.org/)
    - [Visual Studio Code Official Download](https://code.visualstudio.com/)
    - [VSCode R Extension by REditorSupport](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r)
    - [Pandoc Installation Guide](https://pandoc.org/installing.html)
    - [R Extension Settings Documentation](https://github.com/REditorSupport/vscode-R/wiki/Extension-settings)

    ### REditorSupport
    - [Working with renv in VSCode](https://github.com/REditorSupport/vscode-R/wiki/Working-with-renv-enabled-projects)
    - [Interacting with R Terminals in VSCode](https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals)
    - [Interactive Viewers for R in VSCode](https://github.com/REditorSupport/vscode-R/wiki/Interactive-viewers)
    - [R Session Watcher Documentation](https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher)
    - [Code Linting for R in VSCode](https://github.com/REditorSupport/vscode-R/wiki/Code-linting)
    - [Recommended Extensions for R in VSCode](https://github.com/REditorSupport/vscode-R/wiki/Recommended-extensions-and-configuration)
    - [R Debugger Extension](https://marketplace.visualstudio.com/items?itemName=RDebugger.r-debugger)
    - [macOS Installation Notes for R Extension](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS)
    - [VSCode R Language Documentation](https://code.visualstudio.com/docs/languages/r)
    - [REditorSupport VSCode R Wiki](https://github.com/REditorSupport/vscode-R/wiki)
    - [DataNovia R Environment Setup Guide](https://www.datanovia.com/learn/tools/r-in-vscode/setting-up-r-environment-in-vscode.html)
    - [DataNovia Recommended Configurations](https://www.datanovia.com/learn/tools/r-in-vscode/recommended-vscode-configurations-for-r-programming.html)
    - [InfoWorld Guide to R in VSCode](https://www.infoworld.com/article/2267616/how-to-run-r-in-visual-studio-code.html)
    - [Medium Article on R in VSCode](https://medium.com/analytics-vidhya/a-fresh-start-for-r-in-vscode-ec61ed108cf6)
  4. trilin6 revised this gist May 11, 2025. 1 changed file with 38 additions and 0 deletions.
    38 changes: 38 additions & 0 deletions r.code-workspace
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    {
    "folders": [
    {
    "path": "."
    }
    ],
    "settings": {
    // R Basics
    "r.rterm.mac": "/usr/local/bin/radian",
    "r.bracketedPaste": true,
    "terminal.integrated.env.osx": {
    "R_HOME": "/Library/Frameworks/R.framework/Resources",
    "R_BIN": "/usr/local/bin/R"
    },

    // Radian Enhancements
    "r.radian.colorScheme": "monokai",
    "r.radian.autoMatch": true,
    "r.radian.historySearch": true,

    // Advanced Features
    "r.sessionWatcher": true,
    "r.lsp.diagnostics": true,
    "r.plot.useHttpgd": true,
    "r.alwaysSaveHistory": true,
    "r.lsp.debug": false,

    // Formatting
    "[r]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.formatOnSave": true
    },
    "[rmd]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.formatOnSave": true
    }
    }
    }
  5. trilin6 created this gist May 11, 2025.
    211 changes: 211 additions & 0 deletions guide.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,211 @@
    ### 🌟 Introduction
    Using R in Visual Studio Code (VSCode) on macOS offers a lightweight, flexible, and powerful alternative to RStudio. This guide walks you through installing R, configuring VSCode with the official R extension, and setting up advanced tools like `radian` and interactive plotting. Tailored for macOS, it’s perfect for beginners and pros alike! 😎

    ---

    ### 🛠️ Prerequisites
    Before we start, ensure these are installed:

    - **R Programming Language**
    - Grab R (3.4.0+) from [CRAN](https://cloud.r-project.org/).
    - Install via Homebrew for the latest: `brew install R`.

    - **Visual Studio Code**
    - Download from [VSCode Official](https://code.visualstudio.com/).

    - **Python (Optional for Radian)**
    - Usually pre-installed on macOS. If not, use Homebrew: `brew install python` or get it from [Python Official](https://www.python.org/).

    ---

    ### 📦 Installing the R Extension
    Let’s get R running in VSCode!

    1. Open VSCode.
    2. Hit `Cmd+Shift+X` to open the Extensions view.
    3. Search for "R" and install **R by REditorSupport** from the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=REditorSupport.r).
    - **Note**: Stick with REditorSupport.r—it’s the official, community-backed choice over alternatives like Ikuyadeu.r.

    ---

    ### ⚙️ Setting Up the R Environment
    Time to prep R with essential packages!

    1. **Install `languageserver`**
    - Open an R console (type `R` in Terminal or VSCode’s terminal).
    - Run:
    ```R
    install.packages("languageserver", repos="https://cran.r-project.org")
    ```
    - This powers autocompletion and diagnostics.

    2. **Install Bleeding-Edge Packages**
    - Boost functionality with these GitHub-hosted goodies:
    - `rmarkdown` (R Markdown support):
    ```R
    remotes::install_github("rstudio/rmarkdown")
    ```
    - `httpgd` (Interactive plots):
    ```R
    remotes::install_github("nx10/httpgd")
    ```
    - Install `remotes` first if needed:
    ```R
    install.packages("remotes")
    ```
    - **Optional**: Install Pandoc for `rmarkdown` rendering from [Pandoc Official](https://pandoc.org/installing.html).

    ---

    ### 🔧 Configuring VSCode for R
    Lets tweak VSCode for an epic R experience! Access settings with `Cmd+,`.

    #### **Basic Configuration**
    1. **Enable Bracketed Paste**
    - Makes pasting into the R terminal smooth:
    ```json
    "r.bracketedPaste": true
    ```

    2. **Set R Terminal Path**
    - Point to your R executable (default for CRAN R):
    ```json
    "r.rterm.mac": "/usr/local/bin/R"
    ```
    - Check your path with `which R` in Terminal.

    3. **Radian Setup (Enhanced Terminal)**
    - Radian brings syntax highlighting and auto-completion.
    - Install it:
    ```bash
    pip install -U git+https://github.com/randy3k/radian.git
    ```
    - Configure VSCode:
    ```json
    "r.rterm.mac": "/usr/local/bin/radian",
    "terminal.integrated.env.osx": {
    "R_HOME": "/Library/Frameworks/R.framework/Resources",
    "R_BIN": "/usr/local/bin/R"
    },
    "r.bracketedPaste": true,
    "r.radian.colorScheme": "monokai", // Optional: Fancy colors!
    "r.radian.autoMatch": true // Auto-close brackets
    ```
    - Verify paths: `which radian` and `R RHOME`.

    #### **Advanced Configuration**
    Heres a compact yet detailed setup for power users:
    ```json
    {
    "r.sessionWatcher": true, // Monitors R session for autocompletion
    "r.lsp.diagnostics": true, // Enables linting with lintr
    "r.plot.useHttpgd": true, // Interactive plotting with httpgd
    "r.alwaysSaveHistory": true, // Saves R command history
    "r.lsp.debug": false // Disable debug logs unless troubleshooting
    }
    ```
    - **R Session Watcher**: Tracks your workspace for smarter autocompletion ([Session Watcher Wiki](https://github.com/REditorSupport/vscode-R/wiki/R-Session-watcher)).
    - **Diagnostics**: Uses `lintr` for tidyverse-style linting.
    - **Plotting**: Requires `httpgd` installed.

    ---

    ### 📋 Complete `r.code-workspace` File
    Here’s a fully organized workspace file with all settings!

    ```json
    {
    "folders": [
    {
    "path": "."
    }
    ],
    "settings": {
    // R Basics
    "r.rterm.mac": "/usr/local/bin/radian",
    "r.bracketedPaste": true,
    "terminal.integrated.env.osx": {
    "R_HOME": "/Library/Frameworks/R.framework/Resources",
    "R_BIN": "/usr/local/bin/R"
    },

    // Radian Enhancements
    "r.radian.colorScheme": "monokai",
    "r.radian.autoMatch": true,

    // Advanced Features
    "r.sessionWatcher": true,
    "r.lsp.diagnostics": true,
    "r.plot.useHttpgd": true,
    "r.alwaysSaveHistory": true,
    "r.lsp.debug": false,

    // Formatting
    "[r]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.formatOnSave": true
    },
    "[rmd]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.formatOnSave": true
    }
    }
    }
    ```

    ---

    ### 💻 Working with R
    - **Run Code**: Hit `Cmd+Enter` to send code to the terminal.
    - **Projects**: Use `renv` for dependency management ([renv Wiki](https://github.com/REditorSupport/vscode-R/wiki/Working-with-renv-enabled-projects)):
    ```R
    remotes::install_github("rstudio/renv")
    ```
    - **Terminal**: Enjoy `radian` or stick with the default ([R Terminals Wiki](https://github.com/REditorSupport/vscode-R/wiki/Interacting-with-R-terminals)).

    ---

    ### 🎨 Interactive Features
    - **Plots**: View interactive plots with `httpgd` ([Interactive Viewers Wiki](https://github.com/REditorSupport/vscode-R/wiki/Interactive-viewers)).
    - **Data Viewers**: Explore datasets in VSCode.

    ---

    ### 🧹 Code Linting & Formatting
    1. **Linting**
    - Install `lintr`:
    ```R
    remotes::install_github("r-lib/lintr")
    ```
    - Enable:
    ```json
    "r.lsp.diagnostics": true
    ```

    2. **Formatting**
    - Install `styler`:
    ```R
    remotes::install_github("r-lib/styler")
    ```
    - Add to settings:
    ```json
    "[r]": {
    "editor.defaultFormatter": "REditorSupport.r",
    "editor.formatOnSave": true
    }
    ```

    ---

    ### 🐞 Troubleshooting
    - **R Terminal Missing**: Check `r.rterm.mac` with `which R` or `which radian`.
    - **Plot Issues**: Confirm `httpgd` and `"r.plot.useHttpgd": true`.
    - **Language Server Fails**: Reinstall `languageserver` or verify R path.
    - See [macOS Notes](https://github.com/REditorSupport/vscode-R/wiki/Installation:-macOS).

    ---

    ### 🌐 Resources
    - [VSCode R Docs](https://code.visualstudio.com/docs/languages/r)
    - [REditorSupport Wiki](https://github.com/REditorSupport/vscode-R/wiki)
    - [Radian GitHub](https://github.com/randy3k/radian)