Here’s a summary of the steps to configure the R kernel in VSCode on your MacBook Pro for easy reproducibility:
Summary of Steps#
Install Prerequisites
Install Python 3 (if not already installed).
Install R from CRAN.
Set Up a Virtual Environment
python3 -m venv ~/documents/athena/myenv source ~/documents/athena/myenv/bin/activate
Install Jupyter and IRKernel
pip install jupyter jupyter-client R -e "install.packages('IRkernel'); IRkernel::installspec(user = TRUE)"
Ensure R is in the PATH
Add R to your PATH in your
~/.zshrc
:
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.zshrc source ~/.zshrc
Verify Kernel Installation
jupyter kernelspec list
Install VSCode Extensions
Install the Jupyter Extension.
Optionally, install the R Extension for Visual Studio Code.
Configure VSCode to Use the Jupyter Server
Open VSCode.
Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
).Run
Jupyter: Select Interpreter to start Jupyter server
and select the Python interpreter from your virtual environment.
Open or Create a Jupyter Notebook
Open an existing
.ipynb
file or create a new one.
Select the R Kernel
Click on the kernel name at the top right corner of the notebook interface.
Select the
R
kernel from the dropdown menu.
Step-by-Step Commands#
Install Python 3 and R (if not already installed):
Follow the installation instructions for Python 3 and R on your MacBook Pro.
Set Up Virtual Environment:
python3 -m venv ~/documents/athena/myenv source ~/documents/athena/myenv/bin/activate
Install Jupyter and IRKernel:
pip install jupyter jupyter-client R -e "install.packages('IRkernel'); IRkernel::installspec(user = TRUE)"
Add R to PATH:
echo 'export PATH=/usr/local/bin:$PATH' >> ~/.zshrc source ~/.zshrc
Verify Kernel Installation:
jupyter kernelspec list
Install VSCode Extensions:
Open the Extensions view in VSCode (
Ctrl+Shift+X
orCmd+Shift+X
).Install the Jupyter Extension.
Optionally, install the R Extension.
Configure Jupyter Server in VSCode:
Open the Command Palette (
Ctrl+Shift+P
orCmd+Shift+P
).Run
Jupyter: Select Interpreter to start Jupyter server
and select the Python interpreter from your virtual environment.
Open or Create a Jupyter Notebook:
Open an existing
.ipynb
file or create a new one in VSCode.
Select the R Kernel:
Click on the kernel name at the top right corner of the notebook interface.
Select the
R
kernel from the dropdown menu.
By following these summarized steps, you should be able to replicate the setup on your MacBook Pro successfully. If you encounter any issues or need further assistance, please let me know.
.Rhistory#
When you save a session after q()
install.packages("IRkernel")
install.packages("IRkernel")
Sys.setenv(JUPYTER_PATH = "/Users/apollo/Documents/Athena/myenv/bin/jupyter")
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "/Users/apollo/Documents/Athena/myenv/bin", sep=":"))
system2(Sys.getenv("JUPYTER_PATH"), c("kernelspec", "list"))
IRkernel::installspec()
install.packages("IRkernel")
q()
Sys.setenv(JUPYTER_PATH = "/Users/apollo/Documents/Athena/myenv/bin/jupyter")
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "/Users/apollo/Documents/Athena/myenv/bin", sep=":"))
Sys.getenv("JUPYTER_PATH")
system2(Sys.getenv("JUPYTER_PATH"), c("kernelspec", "list"))
IRkernel::installspec()
q()
install.packages("IRkernel")
IRkernel::installspec(user = FALSE) # Use user = FALSE to install system-wide if necessary
IRkernel::installspec(user = TRUE) # Use user = FALSE to install system-wide if necessary
Sys.setenv(JUPYTER_PATH = "/Users/apollo/Documents/Athena/myenv/bin/jupyter")
Sys.setenv(PATH = paste(Sys.getenv("PATH"), "/Users/apollo/Documents/Athena/myenv/bin", sep=":"))
Sys.getenv("JUPYTER_PATH")
system2(Sys.getenv("JUPYTER_PATH"), c("kernelspec", "list"))
jupyter notebook
q()