Automatic packages path detection in Julia - julia

Is there any recommended way to set the Path for installing Julia packages that consider the minor and major versions from the command line or from a .bashrc (or another hidden configuration file)?
I think the variables $(VERSION.major) and $(VERSION.minor) have the required values but they are visible only in a Julia session.
In R one can use a file .Renviron where the package location can be stored in a R_LIBS_USER variable. I wonder if there is anything similar in Julia? Thanks.

Related

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.

R alternative to install.packages() function

Is there any documentation on manually installing a package in a user library when the R.home() path is locked down and incomplete (no etc, no bin, just library?) The system does NOT support shelling out to execute R CMD, which I believe standard R does.
I would like to build existing source packages (from CRAN) and install into a user library directory, so that I can use the library() function and get all the usual namespace and *.Rdx and *.Rdb files.
At the moment, I'm plodding through install.packages, tools::.build_package, and tools:::.install.packages source, using a standard MacOS R and the r source. Hopefully this has been documented in a more user-friendly fashion and my google searches have missed it.
Thanks.
You don't need to use a different install.packages method, rather you only need to specify a writable location for storing packages and give it precedence over the system default one. A simple way to accomplish this is to set an R_LIBS environment variable. For instance, in my .bashrc I have
export R_LIBS='/home/username/.local/lib/R-3.3.3'
Then, by default, all packages are installed here. Further, packages installed both here and the system-wide location will give priority to the ones here when loading.
You can verify that the location is being used by checking .libPaths() in your R session.

Specify different library path for different R version

Different versions of R have installed in the cluster. How can I set different library path for different R version?
UPDATE:
Thanks to #nicola, .libPaths() or library can set library path and help R find the specific location of packages.
Is there any way to do this in a system wide, like some system environment value. So I can start R and find the specific location automatically.

R setting library path via R_LIBS

I have read the R FAQS and other posts but I am a bit confused and would be grateful to know whether I did everything correctly.
In Windows, in order to modify the default library folder I created a file Renviron.site and put inside E:/Programs/R-3.3.0/etc.
The file has only one line saying
R_LIBS=E:/Rlibrary
When I open R and run .libPaths() I see E:/Rlibrary as [1] and the default R library E:/Programs/R-3.3.0/library as [2].
This should mean that from now on all packages I will install will go in E:/Rlibrary but at the same time I will be able to load and use both packages in this folder and those in the default location. Am I correct?
When you load a package via library, it will go through each directory in .libPaths() in turn to find the required package. If the package hasn't been found, you will get an error. This means you can have multiple versions of a package (in different directories), but the package that will be used is determined by the order of .libPaths().
Regarding how .libPaths() is constructed, from ?.R_LIBS
The library search path is initialized at startup from the
environment variable 'R_LIBS' (which should be a colon-separated
list of directories at which R library trees are rooted) followed
by those in environment variable 'R_LIBS_USER'. Only directories
which exist at the time will be included.

R: Updating .libPaths() on Ubuntu

I am trying to follow advice here & here, to update the location where R looks for installed packages. I have updated the variable .Library.site in the /etc/R/Rprofile.site file to include the location of the intended R package library directory:
Sys.setenv(".Library.site" = "~/AppData/R/x86_64-pc-linux-gnu-library/")
However, when I start up R, and do a .libPaths() the location is not appended to the list of library locations. Why?
Three answers:
Your approach is wrong. .libPath() is an R function, not an environment variable. What you do above above cannot work.
Per a consensus with (some members of) R Core, I have been setting the path to three location since circa 2003 for Debian / Ubuntu. That is done below /etc/R/ and you probably saw it.
The easiest to set a per-user directory would be via R_LIBS_USER which I typically comment-out as I like as users on a machine to have consistent paths. You can set it either in the global Renviron, or in the global Renviron.site (better) or in ~/.Renviron (probably best).
You do that via R_LIBS_USER="~/AppData/R/x86_64-pc-linux-gnu-library/".

Resources