Changing R version by a command - r

Is there any possibility how can I change version of R studio by a command ? Let's say I have several versions of R in my computer. Is there any possibility how can I switch between them without going to Tools -> Global options but use some command in console instead?

Related

Streamline building R Windows Binaries for multiple R versions

I am developing R packages for an internal use applications at work. Unfortunately, not everybody is on the same version of R. I want to build Windows binaries of my package to support multiple versions, for example, 3.6.x and 4.0.x R.
I can easily do this by building the package (I use devtools::build(binary = TRUE)), and then change the R version in RStudio, restart, and run again. But this gets very tedious.
Is there a way to streamline this (e.g., my own custom function to build both at once)? I imagine some CI/CD thing is probably best, but this solution would have to be limited to what I can run locally.
Don't do it in RStudio, write a script to do it. It would have commands like these:
/path/to/R3.6.3/R CMD INSTALL --build /path/to/yourpackage
mv yourpackage.*.zip /path/for/R3.6users
/path/to/R4.0.3/R CMD INSTALL --build /path/to/yourpackage
mv yourpackage.*.zip /path/for/R4.0users
You don't need a lot of builds; only the first two parts of the version number (e.g. 3.6 or 4.0) need to match the target system.
You could implement this script in R using system() calls, but it's probably simpler to do it using one of the Windows script languages (.bat or .cmd or whatever).

Using R in Visual Studio Code with conda environment

I would like to use the R environment I installed with conda inside Visual Studio Code (on Macos). First I installed R with conda.
But how do I use/activate the environment in Visual Studio Code? In the settings I can't find the equivalent to "Python: Select Interpreter" or "python.venvPath"
Thanks!
R support in VSCode is handled by a 3rd party extension. The most popular one is R by Yuki Ueda and there is also R Tools by Mikhail Arkhipov
For both of these, you can change the R interpreter to use in the settings.
However, there is no built-in support for Anaconda, mostly because it isn't that popular or necessary in the R community. Most people use the standard R installation instead and most help resources are written for that type of installation: https://cloud.r-project.org/bin/macosx/
It has been 2 years since this entry and the extension still doesn't support conda environments.
For my configuration (I've R installed in a conda environment), I found a pretty painless work around:
open 'vscode'
install the extension and configure it as suggested using the conda paths for both R and, if you have it installed, radian
close 'vscode'
open a terminal
activate your conda environment
start vscode from your terminal using code
After this, everything seems to be up and running correctly. You can start an R terminal using the command palette and, as you run your code, you should be able to see all the information about the environment and namespaces as well as your plots.

new version of R with rstudio

I installed a new version of R but rstudio still uses the old version. The command "which R" is just a shell script and I'm not sure how to get rstudio and the new version of R integrated. R base installed in /usr/share/doc.
Any tips?
Thanks,
Bob
See the RStudio support pages. In particular, for Linux, you have to set the RSTUDIO_WHICH_R environment variable.
As found out in the comments, you're on a Linux system, specifically Linux Mint 17. I can see three basic scenarios here:
You want to ensure RStudio uses a specific version of R when you are launching RStudio from the terminal as a one-time event.
You want to ensure RStudio uses a specific version of R every time you launch RStudio from the terminal.
You want RStudio to use a specific version of R when you launch RStudio from the applications menu (or, equivalently, via something like Synapse).
They are dealt with in turn below. I assume throughout that the path to the R binary you want RStudio to use is /opt/R/3.1.0/bin/R, which you should change as appropriate.
One-time Terminal Launch
After opening a terminal via Ctrl-Alt-T, run
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then, anytime you launch RStudio from the terminal via the rstudio command in that terminal session, it will use the specified R version. However, after you exit, the next time you open the terminal, it will no longer respect that choice.
Every Terminal Launch
Use your favorite text editor to edit the file ~/.bashrc. At the end, on a new line, add
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then, either launch the terminal, or if you already have it open run the command source .bashrc. Then, you can launch RStudio via the command rstudio and it will use the version of R you want.
Launching from the Applications Menu
Use your favorite text editor to edit the file ~/.profile. At the end, on a new line, add
export RSTUDIO_WHICH_R=/opt/R/3.1.0/bin/R
Then you need to log out of your system and log back in. After that, anytime you launch RStudio from the application menu, it will use the specified R version.

Forcing Rstudio to use a specific version of R on linux

My Rstudio (on linux) runs R version 3.3.0 and I don't have a clue what's directing it to do so. I'm using a VM, where my .bashrc file loads R 3.3.1 where I also set the RSTUDIO_WHICH_R env' variable to R 3.3.1 using:
export RSTUDIO_WHICH_R=`which R`
I've also set these two in the .bashrc file of root, but that neither prevents Rstudio from using 3.3.0.
Any idea how to force Rstudio to use the R version I want?
Your solution is almost as it appears in this documentation, but I worry that the shell command expansion doesn't apply when being exported. To find out, what does echo $RSTUDIO_WHICH_R return? (tested, works fine).
Perhaps try executing which R and using that full path as the exported variable.
Update: From that documentation,
Not that in order for RStudio to see this environment variable when launched from the Ubuntu desktop Applications menu (as opposed to from a terminal) it must be defined in the ~/.profile file.

Using StatET with Eclipse in Win64: "no session of R is active in the current workbench window"

What do I do when I get the following error message in Eclipse when trying to launch R?
"no session of R is active in the current workbench window"
I've made a tutorial for installing StatET on my Win64 system, you can find it here (mirror). Although it's no rocket science it's easy to get into issues along the way.
You need to first configure R for your system and then you also need to go into Run > Run Configurations... and add a R Console before you can run it.
You also need to be careful about the Java version that you use. I had to uninstall all my Java, then reinstall the 64-bit before it worked. I guess I could've used the 32-bit, but since I use 64-bit R I thought that it might be a better option (although I think the Eclipse environment and R don't really care about sharing bits)
for me had to select rterm, that displayed the r console/terminal. Then do run , run as -> run in R as script via source
I had the sampe problem.
go to Run > Run Configurations > RStudio
and klick on "Run"

Resources