Why not r via conda?

rstudio
python
anaconda
#1

My office is beginning to expand use of R & is preparing to install R/RStudio on many computers. Since there is a concurrent install of python going on, using the conda distribution, IT wants to know if there's a compelling reason that we shouldn't just have folks use the conda distribution of R/RStudio. My gut on this is no, for package management reasons, but I can't precisely articulate what might go wrong.

Looking for other folks' experiences & recommendations--TIA!

0 Likes

#2

Haven't used it much but when I did there were lots of package version conflicts. I'd be curious to hear how you are going to install these tools on many computers. My initial efforts to combine R and Python resulted in a Docker container: https://github.com/radiant-rstats/docker

I'm hoping that Rstudio will add an option to Rstudio Cloud for python and Jupyter notebook. If this is something you might find interesting add a comment to https://community.rstudio.com/t/equivalent-of-jupyterhub-with-rstudio-cloud

0 Likes

#3

I have no personal experience with using the Anaconda R and RStudio distribution, but I can offer as anecdata some reports of at least one serious problem with anaconda-installed RStudio IDE that have cropped up here. It’s totally murky to me what the source of this problem was (and maybe it wouldn’t have occurred in an IT-managed environment), but it seemed to resolve when people re-installed directly from RStudio-provided downloads.



Also, in at least one instance RStudio folks have remarked here that they don’t support Anaconda installations of the IDE, so I guess you’d be more-on-your-own-than-usual?:

3 Likes

Unable to install olsrr in RStudio but I can install it in R
#4

R with conda works great! Unfortunately, the is 0 or less than 0 support from the rstudio community on this. One commenter on a post of mine said that I was wrong to call conda a package manager. Oh golly.

There are a few tricks to keep in mind:

  1. When you use R with conda you need to stick to conda as much as you can. DON'T LET R INSTALL PACKAGES FOR YOU. In other words ALWAYS USE CONDA TO INSTALL THE PACKAGES YOU NEED unless there is not a conda recipe for that package. In that case, see below.

  2. Take great care in terms of which conda channels you use. After extensive experimentation and discussion with channel maintainers, I have learned the following (and I wish this information was more transparently out there):

  • R versions in different channels are often not compatible as they are compiled with different internals.
  • The anaconda channel is maintained by continuum. The r channel is...well I don't really understand but I think it's some kind of subset of the anaconda channel. These channels are probably compatible.
  • The conda-forge, bioconda, and defaults channels are open-source channels. They are largely compatible with the following caveat. In your .condarc, you should always use the following order: 1. conda-forge, 2. bioconda, 3. defaults. If you stick to that order, you should not have any problems.
  • Do not mix proprietary channels (anaconda,r) with open-source channels (conda-forge, bioconda, defaults). Problems will arise.
  1. When you need packages that are not available in the channel set you are using, you must install them by hand into an external location outside of the conda environment. As an example, I have a directory /home/balter/R35. When I want to install a package by hand, I do install.packages(<some_pkg>, lib='/home/bater/R35). Other install methods such as biocLite and install.github wrap install.packages, so will accept the lib argument even if it's not explicitly noted in the docs.

There is a bit more to this as in the process of installing <some_pkg> other r packages may be installed. The installer will put them into the directory specified with lib. This is ok, but many of the dependencies could actually be installed with conda which is preferable. Consequently, when installing an R package externally (and if you need to do this a lot, then conda may not be the solution for you), I look up the dependencies in the docs and install those first with conda.

Finally, you will need to add your external library to your .lib.Paths. However, you need to make sure your conda path is first. Thus:

.libPaths(new=c('<conda home>/envs/env_name/lib/R/library', '<path to external>')

Finally, I put this function (which you will have to edit somewhat) in my .Rprofile to make sure everything works all the time, which once I figured all this out IT HAS DONE WITH 100% CONSISTENCY AND NO PROBLEMS.

(ds35) balter@little-d:~$ cat .Rprofile
options(repos=structure(c(CRAN="https://ftp.osuosl.org/pub/cran/")))

startCondaEnv = function(env_name, lib='/home/balter/R')
{
        cat("pointing to conda env:", env_name, "and lib location", lib, "\n")

        r_lib_path = lib
        if (env_name == "" || env_name == "base")
    {
                #print("using default base env")
                conda_lib_path = file.path('/home/balter/conda/lib/R/library')
        }else
        {
                conda_lib_path = file.path('/home/balter/conda/envs', env_name, 'lib/R/library')
        }

        #cat('conda_lib_path: ', conda_lib_path, '\n')

        .libPaths(new=c(conda_lib_path, r_lib_path))

        #cat(".libPaths():\n")
        print(.libPaths())
}


current_conda_env = Sys.getenv('CONDA_DEFAULT_ENV')
cat('current_conda_env:', current_conda_env, '\n')

current_conda_prefix = Sys.getenv('CONDA_PREFIX')
cat('current_conda_prefix:', current_conda_prefix, '\n')

if (current_conda_env != "")
{
        r_version = R.Version()
        r_version = paste0(r_version$major, '.', r_version$minor)

        if (r_version == '3.5.1')
        {
                r_lib_path = '/home/balter/R35'
        }else
        if (r_version == '3.4.11')
        {
                r_lib_path = '/home/balter/R34'
        }else
        {
                message("no compatible lib")
                r_lib_path = ''
        }

        #cat("env: ", current_conda_env, ", prefix: ", current_conda_prefix, "\n")
        conda_env_lib = file.path(current_conda_prefix,'lib/R/library')
        startCondaEnv(current_conda_env, lib=r_lib_path)
}else
{
        print("no conda env")
}

Not the most beautiful code, but it works, and if you have any ideas for improvement, please do comment. Obviously, this is for linux and you will need to write your own for Windows.

Best of luck and feel free to respond with more questions as this will help me refine this process which I eventually hope to add to some online docs somewhere.

3 Likes

package install issue with FSA and jupyter -
split this topic #5

2 posts were split to a new topic: package install issue with FSA and jupyter -

0 Likes

closed

This topic has been closed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.
#6
0 Likes