specifying R library path for RKernel in Anaconda Jupyter notebook - r

First let me preface this with the disclaimer that I'm new to R, but a longtime Python power user. Given that I love the conda ecosystem and the Jupyter notebook, I'm trying to set them up as my R development environment as well.
So using the instructions at: https://www.continuum.io/blog/developer/jupyter-and-conda-r I've set up a Jupyter Notbook that using an RKernel that should be hitting the installation of R installed in my Anaconda folder (I would think anyway).
Getting it setup was easy peasy and everything is working great for standard R stuff but my analysis requires some R libraries that are not available in r-essentials channel. No problem, I think I know how to install an R library. I go to "C:\Anaconda\R\bin\x64\Rgui.exe" and install rgdal, dismo, and some other packages. To check my work I looked in C:\Anaconda\R\library and there they are.
But when I run a jupyter notebook from the Anaconda command prompt. And start a new R notebook I get a "Error in library(dismo): there is no package called 'dismo'" Wait a sec, I run a ".libPaths()" from the notebook and it looks like its pointing

You can add .libPaths('path_where_your_packages_are') in a code cell at the beginning of your notebook to tell jupyter where your packages are. For me that was .libPaths('~/R/win-library/3.2') (work-around from discnerd who filed this issue on github).
To find out the path to your packages, just install a random package in R and wait for the location to be printed to the console.
More details (likely specific to my system/installations): When running .libPaths() in R, I got 2 locations: one for which admin rights were required for writing, and one for which admin rights were not required for writing. While packages installed through R land in the location where admin rights are not required, jupyter looks at the location where admin rights are required.

You can find out the path to your library with installed.packages()

Related

Installing R Language on Jupyter Notebook

I've checked all the resources and tutorials from the internet and it seems all are requiring to install Anaconda just to build the R kernel.
Is there a way to add R kernel to my jupyter notebook without installing Anaconda? If so, how?
Thanks!
I've solved my problem, by installing R into my machine. Upon installing, run the application and I follow this tutorial, by just copying the stated command.
Here's the link for the installation of native R.

How best to update / upgrade RStudio inside or underneath Anaconda Navigator?

The version of R Studio that is bundled with the latest release of the Anaconda distribution is over a year old RStudio in Anaconda Navigator, specifically version rstudio-1.1.456. If I check the Rstudio website current RStudio download, it says the latest version is RStudio-1.2.5033.exe.
I want to use the current RStudio release. Anaconda Navigator package manager doesn't give me an option to install any later versions. Also, Anaconda put my R-dedicated virtual environment (which I named Rdev') and installed R in a wierd place too:C:\Users\rlysakow.conda\envs\Rdev\Lib\R\bin`.
My judgement is that R and RStudio are basically UNIX programs that have been ported to Windows, and have all kinds of "leftover" Unix-izms and quirks in the way they reference files, directories, and scripts. Plus, Anaconda makes a lot of choices without always asking the user about where to put things.
It looks like to get a good RStudio update, I must update RStudio from within RStudio, but this will likely break a lot of Anaconda R functionality. RStudio doesn't use Anaconda Navigator's conda program to do the upgrade. The Anaconda Navigator's conda package index will likely not reflect the changes that RStudio makes.
Before I make a likely irreversible and breaking change to Anaconda, can anyone recommend a better way to do this Rstudio update and have Anaconda's package index correctly reflect changes that RStudio will make with executables and packages that it updates and installs?
Please do not recommend something like "ditch Anaconda and just use RStudio for all your R work", because that doesn't allow easy integration with Jupyter Notebook and the conda package manager inside Anaconda. I could install Jupyter Notebook separately, but then I have to manager that outside of Anaconda too. The end users of my application want to use Jupyter Notebook for their R work.

How can I install the R kernel on an AWS SageMaker notebook instance without internet access?

I am trying to install the R kernel on an AWS SageMaker notebook instance that has no internet access. AWS provides documentation on how to install the R kernel on a notebook instance with internet access here. However, I am trying to install the R kernel on a notebook instance without internet access. Their documentation states that r-essentials must be installed. I've tried downloading/installing the r-essentials tar.bz2 archive from the Anaconda package repository. However, it seems like the r-essentials is simply a metapackage and does not contain the actual packages that are to be installed.
Installing r-essentials using the tar.bz2 archive:
Checking if the R kernel exists in the notebook dropdown:
Is there a workaround for this? The goal is to get the R kernel on the notebook instance. Thanks in advance!
Looks like the r-essential tar file is just meta data of list of R packages that need to be installed. Have you tried building the R package manually[1]?
Another possible solution is going through the list of R packages, upload the tar file and install the ones you need.
[1]https://cran.r-project.org/doc/manuals/R-admin.html#Installing-R-under-Unix_002dalikes

Which runtime is getting referenced

I have installed R at following location C:\E_Drive\ProgramFiles\R-3.4.3, so I think R environment installed at C:\E_Drive\ProgramFiles\R-3.4.3 will be used when I run the R console, right? Please correct me if I am wrong.
Now, I install a package using the R console.
Now, I download and install RStudio and from the R console of RStudio if I check whether that package is available or not then I see that it is available. I am wondering, how RStudio's R console reported that package is available, I didn't expect that since C:\E_Drive\ProgramFiles\R-3.4.3 is not on my PATH and in no way is linked RStudio with C:\E_Drive\ProgramFiles\R-3.4.3, so I thought RStudio would be referring its own R environment.
Can you please help me understand how my RStudio is referencing the C:\E_Drive\ProgramFiles\R-3.4.3 R environment.
R normally installs packages in the same directory tree as its own binary, but it can also install them elsewhere. On Windows, this generally happens because regular users often don't have write permission in the Program Files directory. The standard Windows installer also records R's location in the registry, so that it doesn't need to be on the PATH to be found by RStudio.
You can find out where Windows or RStudio found R by running R.home() within R. You can find out where R is finding packages in a particular session by running .libPaths().

How does Anaconda work with installing packages?

I just downloaded anaconda and downloaded their basic R package.
I also got some packages from anaconda, using the anaconda terminal commands that they provide on their website.
My question is -- when I am starting a new R session in r studio, do I still need to install.packages()? Can I just load the package?
When I press libary(rJava) for example -- the R command line doesn't say anything back on whether it was successful, that's why I'm not sure. Thanks.
if you have installed the R packages via the R command line then you can just directly load them. I would recommend that you use the command line rather than R studio.

Resources