Should/can you run R Studio in Conda?

There is conflicting advice on this website as to whether is it ok to run R Studio inside a conda environment. In this post the first commentor says not to use R studio in conda but this other post says its fine.
Googling around Anaconda seems to have documentations for running R Studio in a conda environment but there seems to be nothing official from Posit and it would be nice to know what the best practice actually is.
It seems like you can run R Studio in conda but that you might loose functionality, but its unclear what exactly the issues are.

1 Like

Hi @katchamp -

I think there are a few different issues being conflated here...instead of unpacking all of this, let me say YES, you can use RStudio with conda environments.

In the link above, it demonstrates that you can use use_python to specify the specific version of Python you would like to use. If you already have a conda environment, then that's where you can specify the Python interpreter from that environment.

If you want to create/manage conda environments from RStudio, you can do so with the examples from this link:

Best,
Randy

1 Like

What about using conda environments to manage R packages? Or is it best to use an R specific tool? If so how should one manage both R packages and python packages together?

I would keep Python and R packages in different environments. The Renv package provides tools for managing different R environments.

The benefit of conda for Python is that it provides robust build instructions, so that Python and its related dependencies generally "just work". For R, CRAN enforces this through the package submission process (and R packages in general seem to deal with dependencies better IMO), so in the case of R the benefits are mostly for reproducibility with specific package versions.

Best,
Randy

1 Like

I think there are at least 3 different possible combinations:

  1. Install RStudio into a conda environment as a conda binary
  2. Install RStudio normally, but then install R and the packages you need in a conda environment. Then activate your conda environment and launch RStudio so that it uses your conda-installed R
  3. Manage external conda environments via {reticulate}

Here are my thoughts on each one of these scenarios:

  1. This is the most difficult to achieve. As I recently noted here, it's very difficult to package RStudio into a conda binary. Until someone figures out a good way to do this, this will be an unpleasant experience (outdated RStudio and likely some features won't work as expected)
  2. This is manageable if you are using Linux, macOS, or Docker/Singularity. Install R and the packages you need into a conda env, activate it, and then launch RStudio. You might have to set a few env vars to get everything working right. A user posted last month on how they were able to launch RStudio inside a conda environment on Ubuntu. I also recommend checking out grst/rstudio-server-conda for running RStudio Server from inside a conda env installed in a Docker/Singularity container
  3. As Randy explained above, it's possible to manage external conda envs via {reticulate}. This is fine as a way to get Python packages installed, but it's not a good solution if you want holistic management of all your project's dependencies. And just my personal experience as a long-time conda user, but I have found that trying to manage conda envs via calls to {reticulate} functions to be very frustrating. I find it much easier to run conda commands directly in the terminal

All that being said, I would sum up the situation as:

  • Yes, you can launch RStudio to use R that was installed inside a conda environment
  • But Posit does not officially support this use case, so it might require some tinkering to get it working on your machine

This was helpful.

For some additional context about my use case, I am on a shared Linux high-performance computing cluster. Our server adminstation uses Environment Modules to run software like R, R Studio and Python, which we then access via remote desktop. This means to install R packages we either need to change our libraries or contain them in an environment. The admin team keeps pushing my team to use conda to control our R packages but I also get the sense they are more familar with Python. So I was trying to gain some clarity around what the best practices should be here.

1 Like

If I'm not mistaken, on Linux R packages are installed in the individual user HOME directory, or at the very least, you can set the behavior up to do that. That keeps users from writing over each other's versions, without the unnecessary forcing of trying to get them within conda.

edit: Something to this effect rstudio - Change R default library path using .libPaths in Rprofile.site fails to work - Stack Overflow

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

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