Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

taf.libraries() to load all pkgs in the right order #40

Open
iagomosqueira opened this issue Jul 15, 2023 · 3 comments
Open

taf.libraries() to load all pkgs in the right order #40

iagomosqueira opened this issue Jul 15, 2023 · 3 comments
Assignees

Comments

@iagomosqueira
Copy link

To maintain package dependencies when using taf.library(), it appears we need to call each individual package in the right order, to avoid system copies being loaded. So instead of

library(FLasher)

we need to issue

taf.library(FLCore)
taf.library(FLasher)

to avoid a different version of FLCore from being loaded.

I have tried to code up a function of load all packages in SOFTWARE.bib in the order specified there

taf.libraries <- function() {

  bib <- TAF:::read.bib('bootstrap/SOFTWARE.bib')

  pkgs <- names(bib)

  res <- lapply(pkgs, function(x) do.call("taf.library",
list(package=x)))
}

but rather than sending directly a pull request, I thought it would be good to get some feedback first. This is pretty basic as it stands right now. For example, how to make it work with either bootstrap or boot as folder names, is there any internal function that could return the chosen one?

@iagomosqueira iagomosqueira changed the title taf.library to load all pkgs in the right order taf.libraries() to load all pkgs in the right order Jul 15, 2023
@arni-magnusson
Copy link
Member

Hey, that's an interesting idea. Yep, the internal function boot.dir chooses between "boot" and "bootstrap".

Some SOFTWARE.bib entries are not R packages. One could perhaps check each entry with is.r.package() and run taf.library() if it looks like an R package. That might be cleaner than wrapping each taf.library() call inside try() or something like that?

@iagomosqueira
Copy link
Author

Thanks. I think looking at folders in boot/library might be safe enough

taf.libraries <- function() {

  bib <- TAF:::read.bib(file.path(boot.dir(), "SOFTWARE.bib"))

  pkgs <- names(bib)

  res <- lapply(pkgs, function(x) {
    if(dir.exists(file.path(boot.dir(), "library", x)))
      do.call("taf.library", list(package=x))
    })

  invisible(TRUE)
}

@iagomosqueira
Copy link
Author

Better to use taf.library()

taf.libraries <- function() {

  bib <- TAF:::read.bib(file.path(boot.dir(), "SOFTWARE.bib"))
  
  entries <- names(bib)

  installed <- taf.library()

  pkgs <- entries[entries %in% installed]

  res <- lapply(pkgs, function(x) {
    if(dir.exists(file.path(boot.dir(), "library", x)))
      do.call("taf.library", list(package=x))
    })

  invisible(TRUE)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants