r-lib / pak

A fresh approach to package installation
https://pak.r-lib.org
671 stars 60 forks source link

`pak::local_install_deps()` freezes on last iteration when using in apply* function (Alpine) #697

Open pat-s opened 1 day ago

pat-s commented 1 day ago

The following might be a package-specific+OS-specific edge case but I can't wrap my head around it. (Note: it is unrelated to the fact that the pkg has some graphical deps, running with xvfb-run R results in the same issue.)

For some reason, pak::local_install_deps() always gets stuck at the last iteration here:

ℹ No downloads are needed
✔ 8 deps: kept 8 [214ms]
[1] "0.25-3"
fatal: destination path '/tmp/DoE.base_0.25-3' already exists and is not an empty directory.

→ The package (0 B) is cached.

FREEZE

This only happens for a few selected packages, among which I haven't yet found a common similarity. Interestingly, calling pak::local_install_deps() outside of the apply fun and directly on the source of 0.25-3 works without issues.

Reprex

docker run --rm -it --platform linux/arm64 alpine:3.20 sh

apk add --no-cache R R-dev g++

# 0.8.0.9000 at the time of writing
R -q -e 'install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/devel/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))'

R -q -e 'pak::pak(c("gert", "purrr"))'

R

package_name <- "DoE.base"
gert::git_clone(sprintf("https://github.com/cran/%s", package_name),
  path = sprintf("%s/%s", tempdir(), "tmp1"),
  verbose = FALSE
)
# Retrieve all tags
all_tags <- gert::git_tag_list(repo = sprintf("%s/%s", tempdir(), "tmp1"))
# filter out tags that start with R- (= non-valid ones)
all_tags <- all_tags[!grepl("R-", all_tags$name), ]

unlink(sprintf("%s/%s", tempdir(), "tmp1"), force = TRUE, recursive = TRUE)
tag <- all_tags$name
package_name <- rep(package_name, length(tag))

purrr::walk2(package_name[1], tag, \(x, y) {
  print(y)
  system("git config --global advice.detachedHead false")
  system2("git", args = c(
    "clone", "-q", sprintf("--branch=%s", tail(y, 1)),
    sprintf("https://github.com/cran/%s", x[1]), sprintf("/tmp/%s_%s", x[1], y)
  ))
  pak::local_install_deps(sprintf("/tmp/%s_%s", x[1], y))
})

# works
pak::local_install_deps("/tmp/DoE.base_0.25-3/")
✔ Loading metadata database ... done

→ The package (0 B) is cached.

ℹ No downloads are needed
✔ 8 deps: kept 8 [1s]

It seems like some resolve is stuck, but then I would expect this to happen for any package 🤔 Any idea what might be going on here?