Skip to content

Scripts to unattendendly setup R and python in VSCode so R and python console are set up, debug tools, plot views, install R packages by downloading binaries rather than compiling from source

Notifications You must be signed in to change notification settings

Fr4nzz/Setup-R-and-python-on-VSCode

Repository files navigation

VSCode R & Python Setup

Automated, cross-platform setup for VSCode with R and Python development environments. Install VSCode, R, Python, and all necessary extensions and configurations with a single command.

Features

  • Unattended Installation: One-command setup for complete R and Python development environment
  • Cross-Platform: Works on Linux, macOS, and Windows
  • Architecture Agnostic: Supports x86_64 (amd64) and ARM64 architectures
  • Binary Package Management: Fast R package installation without compilation
    • PPM (Posit Public Package Manager): Default, works on all Linux distributions
    • r2u + bspm: Ubuntu-specific, uses APT for R packages
  • Complete VSCode Integration:
    • R and Python extensions
    • Jupyter support
    • Shiny app support with play button execution
    • Interactive plot viewers (httpgd for R, matplotlib for Python)
    • Debug tools and language servers
    • Optimized keybindings
  • Enhanced Terminals: Optional radian for improved R console

Quick Start

Linux/macOS

Install Everything (R + Python + VSCode):

curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash

R Only:

curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash -s -- --r-only

Python Only:

curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash -s -- --python-only

With r2u (Ubuntu only):

curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash -s -- --package-manager=r2u

Configure Existing Installation (already have VSCode/R/Python installed):

# The script automatically detects existing installations and skips them
# It will still configure VSCode settings, extensions, and keybindings
curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash

Windows

PowerShell (Run as Administrator):

irm https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.ps1 | iex

With Options:

irm https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.ps1 -OutFile install.ps1
powershell -ExecutionPolicy Bypass -File .\install.ps1 -ROnly
# or
powershell -ExecutionPolicy Bypass -File .\install.ps1 -PythonOnly

Note: If you get an error like "running scripts is disabled on this system", see Troubleshooting → PowerShell Execution Policy.

WSL (Windows Subsystem for Linux)

For WSL users: Install VSCode on Windows first, then run the Linux script from your WSL terminal:

# 1. Install VSCode on Windows: https://code.visualstudio.com/
# 2. Install the "Remote - WSL" extension in VSCode
# 3. Run this from your WSL terminal:
curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash

The script automatically detects WSL and guides you through the setup. See Troubleshooting → Running in WSL for details.

Google Antigravity Support

This repository supports Google Antigravity (the new AI-first IDE based on VS Code).

Prerequisites:

  1. Install Google Antigravity manually.
  2. Ensure you can run the antigravity command from your terminal (add it to your PATH if necessary).

Setup Scripts

These scripts will install R/Python/Radian (if missing) and configure Antigravity to use the official Microsoft Marketplace (instead of OpenVSX) so that standard Python and R extensions work correctly.

Windows (PowerShell as Administrator):

irm https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/setup_antigravity.ps1 | iex

Note: If you get an execution policy error, see Troubleshooting → PowerShell Execution Policy.

Linux/macOS (Bash):

curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/setup_antigravity.sh | bash

Note: These scripts do not modify keybindings in Antigravity.

Command-Line Options

Linux/macOS (install.sh)

./install.sh [OPTIONS]

Options:
  --r-only              Install only R and R tools
  --python-only         Install only Python and Python tools
  --package-manager     Choose R package manager: 'ppm' (default) or 'r2u' (Ubuntu only)
  --skip-vscode         Skip VSCode installation (configure existing installation)
  --skip-radian         Skip radian installation (use default R console)
  --non-interactive     Run without prompts (use defaults)
  -h, --help           Show this help message

Windows (install.ps1)

.\install.ps1 [-ROnly] [-PythonOnly] [-SkipVSCode] [-SkipRadian] [-NonInteractive] [-Help]

Parameters:
  -ROnly              Install only R and R tools
  -PythonOnly         Install only Python and Python tools
  -SkipVSCode         Skip VSCode installation
  -SkipRadian         Skip radian installation
  -NonInteractive     Run without prompts
  -Help               Show help message

What Gets Installed

R Environment

  • R (latest version from CRAN)
  • VSCode Extensions:
    • REditorSupport.r - R language support
    • RDebugger.r-debugger - R debugging
    • Posit.shiny - Shiny app support with play button
  • R Packages:
    • languageserver - Code intelligence
    • httpgd - Interactive plot viewer in VSCode
    • shiny - Web application framework
    • shinyWidgets - Enhanced UI widgets for Shiny apps
  • Radian (optional): Enhanced R console with syntax highlighting
  • Watchdog (optional): File system monitoring for Shiny devmode autoreload
  • Binary Package Manager:
    • PPM (default): Works on all platforms
    • r2u + bspm (Ubuntu): APT-based, faster on Ubuntu

Python Environment

  • Python 3 (system package manager or Python.org)
  • VSCode Extensions:
    • ms-python.python - Python language support
    • ms-toolsai.jupyter - Jupyter notebook support
  • Tools:
    • pip - Package installer
    • venv - Virtual environment support

VSCode

  • Visual Studio Code (if not already installed)
  • Configured Settings:
    • R terminal and plot integration
    • Python interpreter detection
    • Optimized editor settings
  • Keybindings:
    • R: Ctrl+Enter (run line/selection), Ctrl+Shift+Enter (run chunk)
    • Python: Ctrl+Enter (run line/selection)
    • Shiny: F5 or play button to run app

Already Have Some Tools Installed?

The script automatically detects existing installations! If you already have VSCode, R, or Python installed:

What the script does:

  • Detects existing installations and skips reinstalling them
  • Shows success messages for already-installed tools
  • Still installs missing VSCode extensions (REditorSupport.r, Posit.shiny, ms-python.python, etc.)
  • Still configures VSCode settings (httpgd plots, radian terminal, interpreter paths)
  • Still sets up keybindings (Ctrl+Enter for R/Python execution)

Example scenarios:

What You Have What the Script Does
VSCode + R + Python installed, but not configured Skips installation, configures everything
VSCode + R installed, need Python Skips VSCode/R, installs Python, configures all
Everything installed, just need Shiny support Skips installation, adds Posit.shiny extension + settings
Fresh system Installs and configures everything

Simply run the script - it will detect what you have and configure what's needed:

./install.sh

Post-Installation

Running Shiny Apps

  1. Open an app.R file in VSCode
  2. Click the Run button (play icon) in the top right
  3. Select "Run Shiny App" from the menu
  4. Or press F5

The app will launch and open in your default browser.

R Plots

Plots automatically appear in the PLOTS panel in VSCode when using:

plot(1:10)
ggplot(data, aes(x, y)) + geom_point()

Python Plots

For matplotlib plots to show in VSCode:

import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.show()  # Opens in VSCode plot viewer

R Package Management

PPM (Posit Public Package Manager) - Default

Fast binary packages for Linux, source for macOS/Windows:

install.packages("tidyverse")  # Installs as binary on Linux

Configuration is automatic. PPM repository is set in ~/.Rprofile or /etc/R/Rprofile.site.

r2u + bspm (Ubuntu Only)

Install R packages via APT (system package manager):

install.packages("tidyverse")  # Uses apt-get behind the scenes

Or directly with apt:

sudo apt install r-cran-tidyverse

Benefits:

  • Instant installation (no compilation)
  • System-wide package management
  • Shared dependencies with system packages

Troubleshooting

PowerShell Execution Policy Error (Windows)

If you get an error like:

"File cannot be loaded because running scripts is disabled on this system"

This is due to PowerShell's default security policy. Here are your options:

Option 1: Use the one-liner (recommended)

The irm | iex command bypasses execution policy automatically:

irm https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.ps1 | iex

Option 2: Bypass policy for a single script

If you need to run the downloaded script with options:

irm https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.ps1 -OutFile install.ps1
powershell -ExecutionPolicy Bypass -File .\install.ps1

Option 3: Change policy for current user (persistent)

Allow scripts from the internet that are signed or from trusted sources:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Then run the script normally:

.\install.ps1

Option 4: Unblock the downloaded file

Right-click the downloaded .ps1 file → Properties → Check "Unblock" → OK. Or use PowerShell:

Unblock-File -Path .\install.ps1
.\install.ps1

Shiny Apps Not Running with Play Button

  1. Ensure Posit.shiny extension is installed:

    code --install-extension Posit.shiny
  2. Restart VSCode

  3. Open app.R file - the play button menu should show "Run Shiny App"

R Plots Not Showing

  1. Verify httpgd is installed:

    install.packages("httpgd")
  2. Check VSCode setting r.plot.useHttpgd is true:

    • Open Settings (Ctrl+,)
    • Search for "r.plot.useHttpgd"
    • Ensure it's checked
  3. Restart R terminal in VSCode

Python Run Button Missing

  1. Reload VSCode window: Ctrl+Shift+P → "Developer: Reload Window"
  2. Verify Python extension is installed
  3. Open a .py file - the play button should appear

radian Not Found (Linux/macOS)

Ensure ~/.local/bin is in your PATH:

echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc

Running in WSL (Windows Subsystem for Linux)

The script automatically detects WSL! Here's how it works:

  1. VSCode Installation:

    • Install VSCode on Windows (not in WSL): https://code.visualstudio.com/
    • Install the Remote - WSL extension in VSCode
    • The code command will automatically be available in WSL
  2. Running the Script:

    # Run from your WSL terminal (Ubuntu, Debian, etc.)
    curl -fsSL https://raw.githubusercontent.com/Fr4nzz/Setup-R-and-python-on-VSCode/main/install.sh | bash
  3. What Happens:

    • If code is found (VSCode already set up): Script configures everything ✅
    • If code is NOT found: Script provides setup instructions and skips VSCode installation
  4. R and Python: Installed in WSL (Linux side), configured to work with Windows VSCode

Recommended WSL Setup:

  • Install VSCode on Windows first
  • Install Remote-WSL extension
  • Open WSL terminal: wsl or use Windows Terminal
  • Run the installation script
  • Open your project: code . from WSL terminal

Manual Installation

If you prefer not to use the automated scripts, see MANUAL_INSTALL.md for step-by-step instructions.

Architecture Support

  • Linux: x86_64, ARM64 (aarch64)
  • macOS: Intel (x86_64), Apple Silicon (ARM64)
  • Windows: x86_64, ARM64

Requirements

Linux

  • Ubuntu/Debian: 20.04+ (recommended)
  • Arch Linux/Manjaro: Latest
  • Fedora/RHEL/CentOS: Recent versions
  • curl or wget
  • sudo access

macOS

  • macOS 10.15 (Catalina) or later
  • Command Line Tools for Xcode

Windows

  • Windows 10 or later
  • PowerShell 5.1 or later
  • Administrator privileges

Contributing

Contributions welcome! Please open an issue or pull request.

License

MIT License - see LICENSE for details.

Credits

Based on scripts from Termux-Fr4nz for setting up VSCode with R and Python in containerized environments.

References

About

Scripts to unattendendly setup R and python in VSCode so R and python console are set up, debug tools, plot views, install R packages by downloading binaries rather than compiling from source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •