Custom conda package not available in R after installing from conda

Hello,

I have recently created a small package (https://github.com/lc5415/HDATDS) and hosted it in conda (creating custom conda-recipe and so forth - https://anaconda.org/lucha6/r-hdatds).

Installing the package from RStudio works fine but when I install from conda (conda install -c lucha6 r-hdatds), open an R session from the terminal and run installed.packages() I cannot see my package listed.

Reproducible example
In terminal:

conda create -n testPackage
conda activate testPackage
conda install -c lucha6 r-hdatds

#open R session
R
#within R
installed.packages() #list installed packages 

I would expect to see a package called HDATDS (in capital letters) but I see no sign of it. Perhaps there is something wrong with my meta.yaml file:

Show meta.yaml file


package:
  name: r-hdatds
  version: 0.1.1

source:
  git_url: https://github.com/lc5415/HDATDS.git

requirements:
    - r-base
  run:
    - r-base
    - r-dplyr
    - r-ROCR
    - r-tidyr
    - r-e1071
    - r-glmnet
    - r-xgboost

about:
  # user-oriented info to be displayed in anaconda.org
  home: https://github.com/lc5415/HDATDS
  license: MIT
  summary: This package was developed as a learning exercise and also to share
   useful functions for the Computational Epidemiology and Translational Data Sciences
   with my colleagues from the MSc in Health Data Analytics & Machine Learning
  license_family: MIT

I believe that if I run devtools::install_github("lc5415/HDATDS") from an R session from the terminal , the package is kept in future sessions but ideally the package should be automatically available from the conda installation.

Hi, and welcome!

Please see the FAQ: What's a reproducible example (`reprex`) and how do I do one? Using a reprex, complete with representative data will attract quicker and more answers. Not required for this type of question, though.

I don't have enough experience using conda as a package manager to offer suggestions to fix this , so all I can essay is that it is best reserved for the job it was designed for, superbly, as a Python package manager.

Hello @technocrat , thanks for your reply. I agree with you that using conda for managing R packages is headache. Unfortunately, the cluster service I use uses conda to manage R packages.

re: reprex thanks for the link, I'm still a beginner when it comes to asking for help online.

1 Like

Wish I could offer more. You may be in a tough spot, but I'm not a package guy, so I hope I'm wrong..

Is your R installation the one installed form conda ?
Can you check your library path ?

In R, .libPaths() will give the library paths where package are installed or looked for. My question is : Do you know if Anaconda install in its own R library path when you use conda install or does it use the same as another R installation ?

I often heard that anaconda R works fine if you stay in conda world. :man_shrugging:

Hope it helps finding clues.

1 Like

Hello! thanks for your reply @cderv , I've investigated the issue making use of .libPaths() and installed.packages() within R, and conda list outside R but I still have not solved the problem.

Activating the environment successfully loads the R version from within the conda environment and the .libPaths() command points at the right path. Despite this, when I try to load my package (library(HDATDS)) R says it's not installed but I am able to load dependencies (e.g. library(xgboost)).

Note: I am no package expert (the reason I am fiddling with a package of my own is purely a learning experience!) so I may have done something wrong in the way I uploaded the package to conda!

I managed to solve it!

The problem was in my build.sh file. I thought that file was not essential but it really is, it's the file that builds your package.

For a basic package with no compilation required it should look like:

#!/bin/bash
echo "Building my custom package..."
$R CMD INSTALL --build .

In the end, my meta.yaml file looked like:

package:
  name: r-hdatds
  version: 0.2

source:
  # simply where it sits in git
  git_url: https://github.com/lc5415/HDATDS.git
  
build:            # from HPC support guy
  skip: True    # [win]
  number: 0

requirements:
  build:
    - {{ compiler('c') }}
  host:
    - r-base
    - r-dplyr
    - r-ROCR
    - r-tidyr
    - r-e1071
    - r-glmnet
    - r-xgboost

  run:
    - r-base
    - r-dplyr
    - r-ROCR
    - r-tidyr
    - r-e1071
    - r-glmnet
    - r-xgboost

test:
 commands:
    # You can put additional test commands to be run here.
   - $R -e "library('HDATDS')"           # [not win]

  # You can also put a file called run_test.py, run_test.sh, or run_test.bat
  # in the recipe that will be run at test time.

  # requires:
    # Put any additional test requirements here.



about:
  # user-oriented info to be displayed in anaconda.org
  home: https://github.com/lc5415/HDATDS
  license: MIT
  summary: This package was developed as a learning exercise and also to share
   useful functions for the Computational Epidemiology and Translational Data Sciences
   with my colleagues from the MSc in Health Data Analytics & Machine Learning
  license_family: MIT

You can have a look at these files in my github repo. Thanks @technocrat and @cderv for suggesting ideas to solve the problem!

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.