pak icon indicating copy to clipboard operation
pak copied to clipboard

Subscript out of bounds in "add_recursive_dependencies(plan)"

Open jonlachmann opened this issue 2 years ago • 8 comments

Hi!

I have been searching for a reasonable way to deploy an R package which has many dependencies, both on CRAN and github. I eventually found pak and consider it to be the best out of the alternatives available. I am however having some problems, and I am unable to debug them in a reasonable way. I get the following error and stack trace:

Error: subscript out of bounds
Type .Last.error.trace to see where the error occurred
> .Last.error.trace

 Stack trace:

 12. (function (...)  ...
 13. base:::withCallingHandlers(cli_message = function(msg) { ...
 14. get("pkg_install_do_plan", asNamespace("pak"))(...)
 15. pkgdepends::install_package_plan(plan = plan, lib = lib, num_work ...
 16. pkgdepends:::add_recursive_dependencies(plan)
 17. pkgdepends:::do(i)
 18. pkgdepends:::do(m)
 19. pkgdepends:::do(m)
 20. pkgdepends:::do(m)
 21. base:::.handleSimpleError(function (e)  ...
 22. h(simpleError(msg, call))
 23. base:::stop(e)
 24. (function (e)  ...

 x subscript out of bounds 

I did try to modify the function pkgdepends:::add_recursive_dependencies() with the only result that R did not want to start at all on that computer. I have not been able to gather any more information as to what is causing this error. Is it something that is known and worked on? Are there any workarounds?

Best regards!

jonlachmann avatar Apr 01 '22 06:04 jonlachmann

What is the code that you are trying to run? What version of pak is this?

gaborcsardi avatar Apr 01 '22 07:04 gaborcsardi

I am doing the following, while located in the base directory of the package that I want to install:

gt <- paste(path.expand("~"), ".github_oauth_token", sep = "/")
github_token <- readLines(gt)
Sys.setenv(GITHUB_PAT=github_token)
pak::local_install(".", ask=F)

I completely broke the R installation of my laptop by trying to rebuild pkgdepends with some debug printing inside the function that crashes. How can I determine what is causing the problems? The package that I am trying to install is proprietary, why I cannot share the code. But if I can receive some guidance on how to debug it I can try to make a reproducible example.

The pak version is either the one you get by doing install.packages("pak") (i.e. the CRAN version) or install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/stable/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch)).

jonlachmann avatar Apr 01 '22 07:04 jonlachmann

I am afraid that you'll have to show us a package for which this fails.

gaborcsardi avatar Apr 01 '22 07:04 gaborcsardi

I understand that, and will try to produce something that can reproduce the problem.

Is it possible to run pak without it going through callr?

jonlachmann avatar Apr 01 '22 07:04 jonlachmann

Is it possible to run pak without it going through callr?

.libPaths(c(file.path(find.package("pak"), "library"), .libPaths()))
prop <- pkgdepends::new_pkg_installation_proposal(".", config = list(library = .libPaths()[2]))
prop$resolve()
prop$solve()
prop$download()
prop$install()

gaborcsardi avatar Apr 01 '22 08:04 gaborcsardi

Hi!

Thanks for the code to run it without callr, it makes it much easier to debug everything.

I have sadly not been able to create a useful reproducible example of the problem. I did however notice something interesting, which might shed some light on the problem I am having. In my script I use remotes to install a package from an URL before installing my own package with pak. It seems that they do not play nicely together, by attaching gdb to the process I could see that it got stuck inside a linear solved dynamic library for some reason. I will continue to investigate to see if I can produce something useful for you! Just wanted to update that I am working towards that!

jonlachmann avatar Apr 04 '22 08:04 jonlachmann

This seems like a different problem to me. It could be an edge case of the solver. The rc version of pak is better at that, try this:

install.packages("pak", repos = sprintf("https://r-lib.github.io/p/pak/rc/%s/%s/%s", .Platform$pkgType, R.Version()$os, R.Version()$arch))

gaborcsardi avatar Apr 04 '22 08:04 gaborcsardi

Will try that too! Thanks!

I may have gotten a clue on what goes wrong. I have one dependency which I have installed from CRAN. It has since been removed from there and I have added it as a remote from github. Is it possible to simulate that a package is installed from CRAN when it is no longer available there?

Sorry for spamming with so many not too informed comments. Hope that I in the end can be helpful at finding the bug!

jonlachmann avatar Apr 04 '22 09:04 jonlachmann