I am trying to build an R package in conda using skeleton. After preparing the environment with the required packages, I execute the following commands
$ conda skeleton cran arules
$ conda build r-arules
The recipe files are generated and everything seems OK, but the build command results into the following error:
Adding in variants from internal_defaults
INFO:conda_build.variants:Adding in variants from internal_defaults
Attempting to finalize metadata for r-arules
INFO:conda_build.metadata:Attempting to finalize metadata for r-arules
Undefined Jinja2 variables remain (['cran_mirror', 'cran_mirror']).
Please enable source downloading and try again.
I've been reading the documentation and searching the Web for a solution to this problem, without success, and I do not know what else to do. ¿Any ideas?
Notes: I've started following this tutorial: http://ihrke.github.io/conda.html but afterwards I have also checked the official conda documentation on building packages and other related docs. I have updated conda (= 4.5.2), as well as conda-build ( = 3.10.1)
I finally find out how to solve my issue in two different ways:
The most straight solution is to specify a cran url using --cran-url option when creating the recipse, as follows:
$ conda skeleton cran arules --cran-url https://mran.microsoft.com/snapshot/2018-01-01/
Another solution is to create a conda-build config file, using yaml. Inside that file we specify the cran mirror, for example:
cran_mirror: https://mran.microsoft.com/snapshot/2018-01-01/
And then, we should use option -m when creating the recipe
$ conda skeleton cran arules -m path/to/conda_build_config.yam
PD: It seems there will be a default cran mirror in the next release of conda-build, according to comments in this pull request
Related
I was trying to use actions in a package I wrote. The issue is that the package actions uses remotes in its setup to install CRAN only packages.
Since the package I am working on depends on a non CRAN package that is present on GitHub, both coverage and R CMD checks fail. I tried to avoid this by naively downgrading to an earlier version of the package in depends but some functions are not exported. I am wondering if someone knows a workaround that might help(I cannot open an issue at actions since their support.md file discourages this).
If your package depends on a non-CRAN package, you must include under Remotes: rather than just Imports: in your DESCRIPTION file. Here you would have:
Imports:
actions
Remotes:
r-lib/actions
This will pass checks, but there is no work around for publishing to CRAN if any of your dependencies are not on CRAN, thus you'll get a warning if any packages are present in the Remotes field.
The alternative using Travis is adding r_github_packages: r-lib/actions to your .travis.yml.
After some time, I have found a workaround that for now is good enough if you want to test for the development version(like I wanted). You should include an install_github command in the check.yaml file. Here's an example:
- name: Install dependencies
run: |
install.packages(c("remotes","testthat"),dependencies=TRUE)
remotes::install_github("tidyverse/dplyr")
remotes::install_cran("covr")
shell: Rscript {0}
The above snippet fixed my issue because I wanted to depend on a future dplyr version. You can view the full yaml file here.
Normally I create conda environments like...
conda env create -f environment.yml
conda activate env_name
Normally I work in Python, where a typical environment.yml simple file might looks like this...
name: env_name
dependencies:
- python=3.7
- pip=19.3
- pandas=0.24.2
- pip:
- scipy==1.2.1
What should the environment.yml file look like to install R packages? The packages are on CRAN
A general rule of thumb is that most R packages have corresponding packages in Anaconda Cloud with the prefix r- added. While the defaults channel covers commonly-used packages, the conda-forge channel has the most thorough coverage of CRAN and has helpful scripts for adding new ones. I would generally recommend prioritizing conda-forge when creating R environments.
For bioinformaticians, all Bioconductor packages are available through the bioconda channel, with a bioconductor- prefix and lowercase. For example, SingleCellExperiment is packaged as bioconductor-singlecellexperiment.
A good place to start is simply searching Anaconda Cloud (example search).
Example
Let's assume you want the tidyverse umbrella package and wish to use R v4.1. A YAML for this would be
name: my_r_env
channels:
- conda-forge
dependencies:
- r-base=4.1
- r-tidyverse
Additional Notes
Avoid using install.packages() from within any R sessions - it is prone to dynamic linking issues due to the R instance's unawareness of compiling inside the environment. This is not an issue for pure R packages, but in that case it should be simple to add the package to conda-forge (takes about 15 mins of work and a ~12-24hr turnaround, IME).
Avoid the RStudio packages from Conda - it is an abandoned project and the old versions are incompatible with newer R versions. This may change once RStudio switches from Qt to Electron. Still, there are better ways to load an environment into RStudio, without having to install the full IDE inside the environment.
I'm following the instructions from https://www.continuum.io/content/conda-data-science in order to build a CRAN-available R package (e.g. synthpop).
conda skeleton cran synthpop
conda build r-synthpop
How can I change the default conda build sequence to install to a different library location, as I don't have permission to install to the default one?
* installing to library ‘/path/to/default/lib’
Error: ERROR: no permission to install to directory ‘/path/to/default/lib’
Also, I'm running conda build from within a virtual env.
Raised this as an issue here: https://github.com/ContinuumIO/anaconda-issues/issues/1562
Hi I was faced with this similar problem recently. After some researches, I wrote one passage about it
https://github.com/alfredzj/Documentations/blob/master/anaconda-set-up.md
I don't think changing location is a good idea.
The --croot option allows installs to a specific location:
conda build --croot /path/to/somewhere/env r-synthpop/
In our case we had two R installs, and the configuration in .Rprofile listed a library location which had restricted write permissions. This location masked the path we gave via --croot. Once we edited .Rprofile we could run conda build with the desired path.
I am trying to run R code in Jupyter and the R Kernel was added. Most of the time, packages can be installed successfully. However, some of the packages, such as RCurl and ggmap, would got error while installing.
Example:
install.packages("RCurl")
Warning message in install.packages("RCurl"):
“installation of package ‘RCurl’ had non-zero exit status”Updating HTML index of packages in '.Library'
Making 'packages.html' ... done
What should I do?
Try to specify CRAN as repository in your install.packages statement when installing RCurl and ggmap. For example:
install.packages("RCurl", repos='http://cran.us.r-project.org')
This Stack Overflow post on installing R packages through Anaconda/Jupyter beyond those included in R essential provides more detail.
(Side note: I had encountered the same issue when trying to install R packages on computer clusters. This solution worked for me.)
use conda comment:
conda install r-RCurl
I kept getting the non-zero exit status when trying to install packages with Jupyter notebook with R kernel and was failing because of multiple dependencies when wanting to install a package. I am not an expert in any of these so please forgive me if I make an error in explaining or if it is a non-issue for you but please feel free to comment to clear things out. I just want to share my success story so hopefully it can help someone else: I am working on a MacBook Pro. Here are the information I get when I run R.version() on my jupyter notebook with R kernel:
$platform 'x86_64-conda_cos6-linux-gnu'
$arch 'x86_64'
$os 'linux-gnu'
$system 'x86_64, linux-gnu'
$language 'R'
$version.string 'R version 3.6.1 (2019-07-05)'
These are the steps to take to fix the issue:
Go to https://anaconda.org/
Search the package name that you are trying to install
Copy the one line that is given to install the package, it should be something like:
Conda install -c r r-caret #conda install -c r r-package_name
NOTE: sometimes during installing packages, you’re asked whether or not you want to continue, so add --y at the end of the above statement to continue, so something like this
Conda install -c r r-caret --y
(I will always add it just to be on the safe side)
Click on the new launcher (+ icon) to create a new notebook with PySpark (once opened it has .ipynp extension)
On the first cell paste the copied line from step 2 and run
Once done, restart the kernel on the current notebook
Restart the kernel on your other notebook with R kernel
Run library(package_name) on your notebook with R kernel (e.x. library(caret))
install.packages("Hmisc", .libPaths(), repos='http://cran.us.r-project.org')
This command will install the packagae in the conda
"/home/user/anaconda3/lib/R/library" and use the cran r repository as source.
Add path in Anaconda
As per this answer,
one can also add additional paths in anaconda to load libraries from (for eg., the location where R studio saves the user-installed packages) with
.libPaths( c( .libPaths(), "~/userLibrary") )
For example, the following worked for me:
In Anaconda :
.libPaths( c( .libPaths(), "C:\Users\name\Documents\R\win-library\3.5") )
When I tried to add anaconda's library path to RStudio, it resulted in errors (The procedure entry point MARK_NOT_MUTABLE could not be located in the dynamic link library << arose 4 times in succession) after installation of a package, though the package seemed to load.
Replace name with your local user folder name
Add/change path in RStudio
A useful link to make changes in default user-installed library paths :
https://www.accelebrate.com/library/how-to-articles/r-rstudio-library
To find out where a package has been installed:
find.package('package_name')
The directions nobody else supplied worked for me, but I found this guide, and it worked. Spent way too much time trying all these when I just needed a few simple commands. https://developers.refinitiv.com/en/article-catalog/article/setup-jupyter-notebook-r
I already had R and python installed, so I skipped to step 3. The only seems to mention windows, but it worked for me on mac as well. After following them I was able to install the packages using install.packages("dplyr", repos = "http://cran.us.r-project.org") in a cell in jupyter.
You have to create a directory in which your package will be and do for eg:
install.packages('ggplot2',loc='your directory')
First Step: You can install the IRkernel packages by running the following command in an R console:install.packages('IRkernel')
Second Step: You will have to make Jupyter see the newly installed R kernel by installing a kernel spec. To install system-wide, set user to False in the installspec command IRkernel::installspec(user = FALSE)
Setup Jupyter Notebook for R
I am having a tough time installing R-packages that are not available in the Anaconda repositories. My attempts so far can be found here How to install R-packages not in the conda repositories?.
Currently, I am trying to build the R-package rafalib for conda by following the instructions from this article under the heading Building a conda R package.
The first part works fine.
conda skeleton cran rafalib
Out:
Tip: install CacheControl to cache the CRAN metadata
Fetching metadata from http://cran.r-project.org/
Writing recipe for rafalib
Done
The build command runs into errors
conda build r-rafalib
Out:
Removing old build environment
Removing old work directory
BUILD START: r-rafalib-1.0.0-r3.2.2_0
Using Anaconda Cloud api site https://api.anaconda.org
Fetching package metadata: ......
Solving package specifications: .
Error: Packages missing in current linux-64 channels:
- r 3.2.2*
- r-rcolorbrewer
I have r 3.2.2-64bit installed via conda and it runs without problems. I also already have r-colorbrewer installed via conda and I can use that package without issues in R. Why am I getting these errors when trying to build a conda package?
I am on Linux (Antergos, an Arch derivative) with kernel 4.4.5-1-ARCH.
UPDATE 2015/04/19
Thanks to this answer, I found out that I could include the dependencies by building them separately in the same directory as the package I want to install. That didn't work for me, but I also read that I can include a channel in the build command with -c, just as when installing. So now I do:
conda build -c r r-rafalib
This gets passed all the dependency problems, but after fetching, extracting and linking packages, it fails. Here is the end of the error message.
Removing old work directory
Source cache directory is: /home/joel/anaconda2/conda-bld/src_cache
Downloading source to cache: rafalib_1.0.0.tar.gz
Downloading http://cran.r-project.org/src/contrib/rafalib_1.0.0.tar.gz
rafalib_1.0.0. 100% |#######################| Time: 0:00:00 4.87 MB/s
Success
Extracting download
Package: r-rafalib-1.0.0-r3.2.2_0
source tree in: /home/joel/anaconda2/conda-bld/work/rafalib
+ mv DESCRIPTION DESCRIPTION.old
+ grep -v '^Priority: ' DESCRIPTION.old
+ /home/joel/anaconda2/envs/_build/bin/R CMD INSTALL --build .
sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook
Command failed: /bin/bash -x -e /home/joel/drafts/r-rafalib/build.sh
The error sh: symbol lookup error: sh: undefined symbol: rl_signal_event_hook is the same as I encounter when using install.packages() as reported here.
There is some related discussion in this thread. I have tried to get around this error by installing different versions of ncurses, including this patched version, and I have tried to link the readline libraries, as suggested here, but I keep running into the same error. I'm quite lost at this point and any help to solve this would be greatly appreciated.
Although I started out with a different problem, the final solution turned out to be the same as I posted elsewhere How to install R-packages not in the conda repositories?. I am adding it here for completeness.
In the end, I got around the rl_event_hookproblems by following the approach recommended here and symlinking anaconda's libreadline to the system one:
mv ~/anaconda3/lib/libreadline.s.6.2 ~/anaconda3/lib/libreadline.s.6.2.bak
ln -s /usr/lib/libreadline.so.6.3 ~/anaconda3/lib/libreadline.s.6.2
I am still having troubles installing some dependency heavy R-packages due to failure to load shared objects when using install.packages() from withing R. However, simpler packages work fine and I can get most of the dependency heavy packages from anacondas R-repositories.