pharmaR / regulatory-r-repo-wg

Package consensus for regulated industries
https://pharmar.github.io/regulatory-r-repo-wg
27 stars 3 forks source link

Ensure PACKAGES are discovered via `available.packages()` #88

Open dgkf opened 2 months ago

dgkf commented 2 months ago

Following on #74,

@borgmaan had mentioned that the modified PACKAGES file is not getting picked up by available.packages(repos = "file:.").

@llrs suggested a few helpers from the tools package that might be able to help with this.

llrs commented 2 months ago

The tools::*_PACKAGES doesn't place automatically the files where they should be. This is responsibility of the repository organization (and maybe of available.packages to find it), and they are usually place in <repo_url>/src/contrib/{PACKAGES,PACKAGES.in,PACKAGES.rds,PACKAGES.tar.gz} (This is for both CRAN and Bioconductor).

Instead of <OS>/<R-version>/<pkg>/src/contrib/PACKAGES as in the POC it should be in the top level of the repository (the src/contrib/PACKAGE* part). However, available.packages if used with a local file repos = "file:...." searches it on that directory : .../PACKAGES. See the source code of utils::available.packages around line 22.

dgkf commented 2 months ago

Ah, of course.

This snippet from @borgmaan's script

https://github.com/pharmaR/repos/blob/21fae7094a72a0f7863f66352455b9ea19e5a5ed/dev/merge-riskscore.R#L26-L28

Should instead be

- setwd(file.path(here::here(), "ubuntu-22.04/4.4"))
+ setwd(file.path(here::here(), "ubuntu-22.04/4.4/riskscore"))
  options(repos = c("Local Repo" = "file:."))

Such that available.packages() can append /src/contrib and discover the PACKAGES file.

I'll need to test it out, but I'm confident this is at least part of the issue here.

llrs commented 2 months ago

I am not sure I explained myself well: If a file:. is provided it will search for PACKAGES in that folder without appending /src/contrib.

There are two options:

1) The PACKAGES file should be in a different location:

Instead of /ubuntu-22.04/4.4/src/contrib/PACKAGES it should be in /src/contrib/PACKAGES. It is assumed that a package in a repository will be build/delivered for all the OS (but that is another discussion):

   + file.rename(file.path(here::here(), "ubuntu-22.04/4.4/riskscore/src/contrib/PACKAGES"), 
   +             file.path(here::here(), "PACKAGES"))
   - setwd(file.path(here::here(), "ubuntu-22.04/4.4"))
   + setwd(file.path(here::here())
     options(repos = c("Local Repo" = "file:."))

2) If using available.packages locally it should point to the folder where PACKAGES is.

So it either change the working directory to where it is executed:

   - setwd(file.path(here::here(), "ubuntu-22.04/4.4"))
   + setwd(file.path(here::here(), "ubuntu-22.04/4.4/riskscore/src/contrib/"))
     options(repos = c("Local Repo" = "file:."))

Or it points to where the file is:

     setwd(file.path(here::here(), "ubuntu-22.04/4.4"))
   - options(repos = c("Local Repo" = "file:."))
   + options(repos = c("Local Repo" = "file:./riskscore/src/contrib/"))

Of course this needs to be tested.

dgkf commented 2 months ago

Ah, I see. You explained it perfectly fine, I just failed to grasp that detail. Thanks for the emphasizing the part I misunderstood.

llrs commented 1 month ago

Going back to this after the pharmapkgs package. Being the working directory the https://github.com/pharmaR/pharmapkgs/ package, this works:

path <- file.path(package = getwd(), repo = "inst/repos/ubuntu-22.04/4.4")
ap2 <- available.packages(
  repos = c(pharmapkgs = file.path("file://", path)), 
  fields = readLines(file.path(path, "src", "contrib", "RISKFIELDS"))
)