Search code examples
razurepackage-development

Add r-package dependency of remote repository (Azure)


I have a remote repository in Azure, e.g. https://dev.azure.com/devops/Playground/_git/RTest. In this repository are different R packages, e.g. pkg1, pkg2. I can install package pkg1 like this remotes::install_git("https://dev.azure.com/devops/Playground/_git/RTest", git = "external", subdir = "pkg1", ref = "main")

Now pkg2 has the dependency of pkg1, so that in the DESCRIPTION file it is mentioned as Imports, e.g.:

Imports:
    dplyr,
    pkg1 (>= 0.0.0.9000)
Remotes:
    git::https://dev.azure.com/devops/Playground/_git/RTest

Now I have the problem that, if I want to install pkg 2 like this remotes::install_git("https://dev.azure.com/devops/Playground/_git/RTest?path=pkg1", git = "external", subdir = "pkg2", ref = "main") I get Failed to install 'unknown package' from Git: Command failed (128) I suspect that the entry under Remotes does not work. What do I need to change?


Solution

  • The issue arises because the Remotes field in pkg2’s DESCRIPTION does not clearly specify the subdirectory for pkg1 within the same Azure DevOps repository.

    As @Konrad Rudolph commented when you install a package like pkg2 that depends on pkg1 (in a subdirectory), the installation fails because remotes cannot resolve subdirectories in the same Git repository.

    Manually install the dependent package (pkg1) first, and then install pkg2.

    Install pkg1 Manually:

    remotes::install_git("https://dev.azure.com/devops/Playground/_git/RTest",
                         git = "external",
                         subdir = "pkg1",
                         ref = "main")
    

    Install pkg2:

    remotes::install_git("https://dev.azure.com/devops/Playground/_git/RTest",
                         git = "external",
                         subdir = "pkg2",
                         ref = "main")
    
    • Manual installation of dependencies is required.

    • If this process is repeated frequently, automate it with a script to install both pkg1 and pkg2 sequentially.

    Automation Script:

    install_with_deps <- function(repo_url, subdirs, ref = "main") {
      for (subdir in subdirs) {
        remotes::install_git(repo_url,
                             git = "external",
                             subdir = subdir,
                             ref = ref)
      }
    }
    
    install_with_deps("https://dev.azure.com/devops/Playground/_git/RTest",
                      c("pkg1", "pkg2"))