Rstudio and R in command window in anaconda have different enviroments - r

I have a confusion when using R inAanaconda. I created an environment called "rstudio_env" and installed Rstudio in this environment. So far so good.
When I use Rstudio, I just open it without activating the "rstudio_env" and I also installed a lot of packages here. After updating the R through Rstudio, my new home path in Rstudio changes to some local default path. For example, the original .libPaths() = "C:/Users/someuser/.conda/envs/rstudio/lib/R/library" and new .libPaths()= "C:/someuser/Document/R/R-4.0.2/library".
Now when I use Rstudio, I have the new path. When I use R in the "rstudio_env" in conda, I still have the old path. This really confuses me, because I want to have the same libraries for both approaches. Why the updating changes the path of RStudio rather than only updating the contents?
I am too lazy to activate the "rstudio_env" when using Rstudio. That might be the reason for the conflict. But for now, how can I make the libraries consistent? I know I can change .libPaths manually, but are there other ways, some clearer ways?

I just reinstalled everything and made everything clean

Related

How should I upgrade R properly to keep older versions running [Windows]?

I more or less follow this guideline:
Run installr::updater() from ../R-4.0.0/bin/x64/Rgui.exe (as suggested if you run it from RStudio)
Update all packages (check the "update all packages" box from installr::updater())
Change Windows system environment variable R_LIBS in my case to ..\R\R-4.0.x\library.
If I want to switch the R vesion from RStudio, I need to
Set Tools -> Global Options -> General -> R version AND
change R_LIBS to the correct place. (If you forget this, .libPaths() has more than one entry.)
So my questions are:
Is that process correct? Do I miss anything?
What about changing Rtools when switching between major R-versions, see e.g. here?
It seems installr::updater() does not update the packages, although I check the "update all packages" box. (We observed that behaviour on two different laptops.)
It seems, .Rprofile, .Renviron, and Rprofile.site play a crucial role, see RStudio. Last time, everything worked fine, .Rprofile and .Renviron were empty and I had to add the line .libPaths("path2/R-4.0.4/library") to Rprofile.site. It seems you can use usethis::edit_r_profile() to finde those files.
Background: I had this question which was reproducible before I upgraded R to 4.0.2, but I realized, that after switching between
R 3.5.1, 4.0.0 and 4.0.2 back and forth for testing it is not reproducible anymore.
Thus I think, that my update-process was error-prone.
Two years later, I more or less follow this process with success:
(Windows: Make sure R and RStudio are located C:\. Otherwise you run in trouble with .libPaths()!)
Run installr::updater() from C:/R-4.x.y/bin/x64/Rgui.exe (as suggested if you run it from RStudio)
Update Windows PATH variables
Update all packages (check the "update all packages" box from installr::updater())
Keep packages at the old R-version if you like
If you follow this process, R_LIBS, .Rprofile, and .Renviron should have no impact (it seems).

Anaconda installation of R interfers with regular R installation?

Probably a very basic question for someone who knows what they're doing.
I installed anaconda and jupyter notebooks, and now which R returns /opt/anaconda3/bin/R, rather than /usr/local/bin/R as it did before.
How do I change this back so that RStudio uses /usr/local/bin/R, but preferably without deleting files, editing PATH environment variable, or moving files/binaries around (I am open to suggestion, but prefer a 'best practice' so that anaconda/notebooks work if I need them).

Leaving one library path for R on ubuntu

I am using ubuntu 14.04. I want to set up myself just one library path for R where all of the packages would be installed. I tried setting up environment variables R_LIBS, R_LIBS_USER in .bash_profile (of course running source ~/.bash_profile afterwards), tried adding .libPaths(.libPaths()[1]) to Rprofile.site, but the only thing that I achieve is that my own library is added to 3 other already present ones. Due to this I am getting errors when some packages are from other R version that was previously installed. I want to leave just one library path and prevent R from searching in all others. I found several threads about the issue but neither of them worked for me:
Remove a library from .libPaths() permanently without Rprofile.site
https://community.rstudio.com/t/reinstalling-packages-on-new-version-of-r/7670
I can try just uninstalling all of the packages and reinstalling them over, but I kind of want everything to be structured and organized anyway. I do not like very much that R shuffles libraries into different folders and want to have just one or max two that were defined solely by me.

Building Tools are missing in RStudio

First of all, I am working on a Mac. I am trying to install Blotter from GitHub. I found several descriptions of how to do that but my RStudio tells me that I am missing Building tools and gives me a link (https://www.cnet.com/how-to/install-command-line-developer-tools-in-os-x/) where it is described to do that. So far so good. I downloaded Xcode and the command line tools for Mac and installed those. Nothing changed even after restarting R. Then I found this https://cran.r-project.org/bin/macosx/tools/. I installed it and during that, it told me that I had to do the following
"This package will install clang 6.0.0 for OS X 10.11 (El Capitan) or higher with OpenMP support in /usr/local/clang6
In order to use this compiler you have to add /usr/local/clang6/bin to the PATH environment variable such as
export PATH=/usr/local/clang6/bin:$PATH"
So I changed the environmental variable path as follows http://blog.tonytsai.name/blog/2018-05-07-setting-path-variable-for-gs-command-in-rstudio/.
How I changed the PATH variable.
Again I restarted R but still, nothing changed. I still get the notice that the building tool is missing.
Somehow it seems to me that I installed everything correctly but R doesn't recognize the Programmes. Does anyone have an idea? I tried to search for settings to tell R that I installed the command line tool but couldn't really find anything helpful.
Ok, a bit of an update.
Best I can see it that Blotter is built and stored on R-Forge packages under a package called RStrategist
In R console type/cut & paste this.
install.packages('RStrategist',repos='http://R-Forge.r-project.org')
See R forR-Forge for more details. Once this has been installed run instead.
library(RStrategist)
Unfortunately, I am not willing to install this package and see if it works mainly because 1) don't need it nor know how to use it, 2) not sure how good packages are from R-forge, though it seems legit, but, this brings me back to point one.
So before i read the updated answer of Conrad Thiele i was trying around bit. Basically i deleted R, R Studio, Xcode and Command Line tools. Then i installed Xcode, Command Line tools, R and RStudio. Then i followed the notice on https://cran.r-project.org about the tools and installed both stated tools. As mentioned in the original question the Clang package tells you to change the Environmental Variable. And there was the mistake i believe. I originally simply pasted "PATH=/usr/local/clang6/bin:$PATH" into the the ".Renviron" file. With reading up online i noticed that "export PATH=/usr/local/clang6/bin:$PATH" is actually a Command for the Mac Terminal. After executing it, it sill didn't work but then i remembered that i still had the Path "PATH=/usr/local/clang6/bin:$PATH" in the the ".Renviron" file. Once i deleted that it worked. So i guess the key was that with changing the Environmental Variable correctly R found the connection with the right tool. Patients paid off.

R: combining mutiple library locations with most up-to-date packages

Question: How do I move all of the most up-to-date R packages into one simple location that R (and everything else) will use from now and forever for my packages?
I have been playing around with R on Ubuntu 10.04 using variously RGedit, RCmdr, R shell, and RStudio. Meanwhile, I have installed packages, updated packages, and re-updated packages via apt, synaptic, install.packages(), etc... which apparently means these packages get placed everywhere, and (with the occasional sudo tossed in) with different permissions.
Currently I have different versions of different (and repeated) packages in:
/home/me/R/i486-pc-linux-gnu-library/2.10
/home/me/R/i486-pc-linux-gnu-library/2.14
/home/me/R/i486-pc-linux-gnu-library/
/usr/local/lib/R/site-library
/usr/lib/R/site-library
/usr/lib/R/library
First - I'm a single user, on a single machine - I don't want multiple library locations, I just want it to work.
Second - I am on an extremely slow connection, and can't keep just downloading packages repeatedly.
So - is there an easy way to merge all these library locations into one simple location? Can I just copy the folders over?
How do I set it in concrete that this is and always will be where anything R related looks for and updates packages?
This is maddening.
Thanks for your help.
Yes, it should almost work to just copy the folders over. But pre-2.14 packages WITHOUT a NAMESPACE file probably won't work in R 2.14 where all packages must have a namespace...
And you'd want to manually ensure you only copy the latest version of each package if you have multiple versions...
If you type .libPaths(), it will tell you where R looks for packages. The first in the list is where new packages are typically installed. I suspect that .libPaths() might return different things from RStudio vs. Rcmd etc.
After piecing together various bits of info here goes: A complete moron's guide to the R packages directory organization:
NB1 - this is my experience with Ubuntu - your mileage may vary
NB2 - I'm a single user on a single machine, and I like things simple.
Ubuntu puts anything installed via apt, or synaptic in:
/usr/lib/R/site-library
/usr/lib/R/library
directories. The default vanilla R install will try install packages here:
/usr/local/lib/R/site-library
Since these are system directories the user does not have write privileges to, depending on what method you are interacting with R you might be prompted with a friendly - "Hey buddy - we can't write there, you want us to put your packages in your home directory?" which seems innocent and reasonable enough... assuming you never change your GUI, or your working environment. If you do, the new GUI / environment might not be looking in the directory where the packages were placed, so won't find them. (Most interfaces have a way for you to point where your personal library of packages is, but who wants to muck about in config files?)
What seems to be the best practice for me (and feel free to correct me if I'm wrong) with a default install setup on Ubuntu, is to do any package management from a basic R shell as sudo: > sudo R and from there do your install.packages() voodoo. This seems to put packages in the usr/local/lib/R/site-library directory.
At the same time, update.packages() will update the files in /usr/lib/R/site-library and usr/lib/R/library directories, as well as usr/local/lib/R/site-library
(As for usr/lib/R/ division, it looks like /library/ has the core packages, while /site-library/ holds anything added, assuming they were installed by apt...)
Any packages previously installed and in the wrong place can be moved to the /usr/local/lib/R/site-library directory (assuming you are sudoing it) just by moving the directories (thanks #Tommy), but as usr/lib/R/ is controlled by apt - best not add or subtract anything from there...
Whew. Anyway - simple enough, and in simple language. Thanks everyone for the help.

Resources