I would like to install a local R package into a conda environment. The package is not on CRAN or github (and not on any conda channel).
For packages on CRAN this is relatively straightforward:
conda skeleton cran <pckg>
conda-build r-<pckg>
conda install --use-local r-<pcgk>
For packages on github this works similarly: install R package from github using "conda" (apart from some issues of versions requiring tags).
conda skeleton cran <url>/<pcgk>
conda-build r-<pckg>
conda install --use-local r-<pcgk>
However, I cannot get this to work with a local package (the package builds without problems using R CMD build). This is what I have tried:
conda skeleton cran <path>/<pcgk>
Connects to cran and then (of course) does not find the package.
conda skeleton cran --cran-url <relative_path>/<pckg> <pckg>
throws an error with:
requests.exceptions.MissingSchema: Invalid URL '<relative_path>/<pckg>/src/contrib/': No schema supplied. Perhaps you meant http://<relative_path>/<pckg>/src/contrib/?
conda skeleton cran <absolute_path>/<pckg> <pckg>
Throws:
File "/home/myuser/.conda/envs/myenv/lib/python3.9/site-packages/conda_build/skeletons/cran.py", line 743, in package_to_inputs_dict
pkg_name = re.match(r'(.*)_(.*)', pkg_filename).group(1).lower()
AttributeError: 'NoneType' object has no attribute 'group'
And lastly:
conda skeleton cran --cran-url <absolute_path>/<pckg> <pckg>
Throws:
File "/home/myuser/.conda/envs/myenv/lib/python3.9/site-packages/requests/sessions.py", line 742, in get_adapter
raise InvalidSchema("No connection adapters were found for {!r}".format(url))
requests.exceptions.InvalidSchema: No connection adapters were found for '<absolute path>/<pckg>/src/contrib/'
Is this not possible with conda? Or am I making a mistake?
Here someone tried to write the skeleton files for a local package themselves, but it seems without success.
If you can upload your R package to your private github repository, then you could proceed with the common conda skeleton cran <github_pckg_http_or_ssh>.
conda will ask (internally by git, I think) for your password to retrieve the code.
Related
In my Dockerfile I have the following lines:
FROM rocker/verse:latest
RUN R -e "install.packages(c('R.utils'), repos = 'https://cran-archive.r-project.org')"
When I run docker build . I got:
> install.packages(c('R.utils'), repos = 'https://cran-archive.r-project.org')
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
Warning: unable to access index for repository https://cran-archive.r-project.org/src/contrib:
cannot open URL 'https://cran-archive.r-project.org/src/contrib/PACKAGES'
Warning message:
package ‘R.utils’ is not available (for R version 4.0.2)
I'm new to Docker, not too sure what I'm doing wrong. I put https://cran-archive.r-project.org/src/contrib/PACKAGES in browser and it couldn't load, should I try a different repo URL?
Thanks!
Try any of the advertised mirrors, and they should have the most recent release of R.utils for your version of R-4.0.2.
That CRAN mirror is specifically for old versions of R. Since your version of R (4.0.2) is not old, it is not found there. That cran-archive is intended for R versions without support for those packages (ergo the "archive" label, I suspect).
From the R FAQ 2.10:
Since March 2016, “old” material is made available from a central CRAN archive server (https://CRAN-archive.R-project.org/).
Or perhaps from the R for Mac OS X page:
Package binaries for R versions older than 3.2.0 are only available from the CRAN archive so users of such versions should adjust the CRAN mirror setting (https://cran-archive.r-project.org) accordingly.
Both of these suggest that repos = 'https://cran-archive.r-project.org' should be used for old versions of R, but your error reports R-4.0.2 (not old)
yes, you have to mention the full path to the repo. https://cran.r-project.org/src/contrib/R.utils_2.9.2.tar.gz use this repo link to get R.util.
You can also run the command sudo apt-get install -y r-cran-r.utils to install R.utils
any one can suggest how to use conda in Linux to install R package from github?
Thanks!
According to this: https://github.com/conda/conda/issues/6674
You can create your own conda skeleton of a github derived R-package much as you would for a CRAN package.
Try doing
conda skeleton cran <github_url>
conda build --R=<my_r_version> r-<lower-case-package-name>
Then upload the built conda package to your own anaconda repository.
This will fail if any of the dependencies of the package are absent from the anaconda repos that you have access to. So you might have to conda-build a few other packages along the way.
Alternatively, you could install it directly with devtools::install_github(github_url, dependencies = FALSE). If you do go down this route, please ensure that any conda-available dependencies for the github package are already installed.
If you don't use dependencies = FALSE R will install.packages a bunch of updates. (As far as I can tell) When you install.packages a pre-installed package some_package in a conda env (eg, to update it) and then check conda list <some_package> on your current env, it will show the version that was installed by conda, rather than the updated version.
Edited build command, following #rpanai s suggestion
any one can suggest how to use conda in Linux to install R package from github?
Thanks!
According to this: https://github.com/conda/conda/issues/6674
You can create your own conda skeleton of a github derived R-package much as you would for a CRAN package.
Try doing
conda skeleton cran <github_url>
conda build --R=<my_r_version> r-<lower-case-package-name>
Then upload the built conda package to your own anaconda repository.
This will fail if any of the dependencies of the package are absent from the anaconda repos that you have access to. So you might have to conda-build a few other packages along the way.
Alternatively, you could install it directly with devtools::install_github(github_url, dependencies = FALSE). If you do go down this route, please ensure that any conda-available dependencies for the github package are already installed.
If you don't use dependencies = FALSE R will install.packages a bunch of updates. (As far as I can tell) When you install.packages a pre-installed package some_package in a conda env (eg, to update it) and then check conda list <some_package> on your current env, it will show the version that was installed by conda, rather than the updated version.
Edited build command, following #rpanai s suggestion
I would like to install a package when using the latest R version in RStudio.
In particular the quantstrat package
Is that possible?
This is the R latest version I have 3.4.1
my error message:
Warning in install.packages :
package ‘quantstrat’ is not available (for R version 3.4.1)
Because quantstrat build-fail at R-Forge, you can't get the pre-build file(.tar.gz). You can get the code from github and build by yourself.
install.packages("devtools")
require(devtools)
install_github("braverock/blotter") # dependency
install_github("braverock/quantstrat")
Can you provide the installation code that produced that error message? Are you trying to install it from CRAN?
That doesn't appear possible.
A post from 2014 states it's not on CRAN
quantstrat is a R package ... still under heavy development and can’t be installed from CRAN yet. You can install it from source and the process is straightforward.
It's not on the current list of available CRAN packages
It's R-Forge page states the current version 'Failed to build'.
You could download the previous version (and its dependency) from R-Forge at
http://download.r-forge.r-project.org/bin/windows/contrib/3.2/quantstrat_0.9.1739.zip and
http://download.r-forge.r-project.org/bin/windows/contrib/3.2/blotter_0.9.1741.zip
(or get the Linux tar.gz files). Assuming they're saved in your personal Downloads folder, install it in R with
install.packages("~/Downloads/blotter_0.9.1741.zip", repos = NULL)
install.packages("~/Downloads/quantstrat_0.9.1739.zip", repos = NULL)
According to that first link, you'll need to install these prereqs first, if they're not already:
install.packages("FinancialInstrument")
install.packages("PerformanceAnalytics")
install.packages("foreach")
Edit: see the comment below from #brian-g-peterson for how the current deployment avenue uses GitHub. https://github.com/braverock/quantstrat
usually I install R packages from CRAN mirrors, but some of them give me problems. This almost always happens with packages strongly interacting with the system (e.g. rgl, cairoDevices etc). If I well understood when I install packages from the Ubuntu repo with
apt-get install r-cran-rgl
these will be installed in /usr/lib/R/site-library directory. For a number of packages installed in /usr/lib/R/site-library when I do update.packages(ask=FALSE) from R (working under sys admin) I get the following type of messages:
Warning: package 'ggplot2' in library '/usr/lib/R/site-library' will not be updated
I presume that this happens because the version on the cran is newer than the one on the ubuntu repos. But, the rgl package is installed
in '/usr/lib/R/site-library', however when I invoke
update.packages(ask=FALSE)
R download and tries to install a new version of rgl although the one installed is the last one available on ubuntu repos. By the way it tries to install and it fails for some error.
Therefore, what I don't understand is why it doesn't try to update ggplot2 while it tries to update rgl when both have been installed via apt-get and both have the last release number appearing on the ubuntu repos.
Thanks
Pierre