The steps below will walk you through creating an R virtual environment and kernel so that it may be used in your notebooks.
If you're not already logged in, follow the steps found here. In the upper-right corner, click the New button and select Terminal.
In the Terminal, enter the command below to create a virtual environment. In this example,
r_env is the name used for the virtual environment, but you may name this whatever you'd like.
Press return when asked to proceed. All packages needed by the virtual environment will be downloaded and installed.
Note: This will install the default R interpreter and the R Essentials bundle. If you need a more custom installation, please refer to https://docs.anaconda.com/anaconda/user-guide/tasks/use-r-language.
source activate r_env to activate your virtual environment. Again, you may have used a different name, so substitute as appropriate. You should now see a prompt with the name of your virtual environment in parenthesis as shown.
Once inside the virtual environment, start R by simply typing
R and pressing Return. You will see some R version information and help text, followed by a prompt as shown:
Enter the command
IRkernel::installspec(). This creates an R kernel which will now be available in Jupyter.
Note: This will install a kernel with the name "ir" and a display name of "R". If you need a more custom installation, please refer to https://github.com/IRkernel/IRkernel/.
Navigate back to the Home tab. Make sure to first refresh the page. Next, click the New button and select the name of your kernel, which is R in this example.
You can now run cells with R code as shown.