pak icon indicating copy to clipboard operation
pak copied to clipboard

Remote sessions ignore pkgdepends config

Open heavywatal opened this issue 3 years ago • 5 comments

I am trying to achieve forced binary installation on macOS as suggested in #318. Now pkgcache::meta_cache_list("Matrix") on intel mac shows three rows: available binary (1.5-0), latest source (1.5-1), and recommended (1.4-1).

> pkgcache::meta_cache_list("Matrix")
  package version      depends   suggests                   license
    <chr>   <chr>        <chr>      <chr>                     <chr>
1  Matrix   1.5-0 R (>= 3.5.0) expm, MASS GPL (>= 2) | file LICENCE
2  Matrix   1.5-1 R (>= 3.5.0) expm, MASS GPL (>= 2) | file LICENCE
3  Matrix   1.4-1   R (>= 4.3) expm, MASS GPL (>= 2) | file LICENCE
                                         imports linkingto          archs
                                           <chr>     <chr>          <chr>
1 methods, graphics, grid, stats, utils, lattice      <NA> Matrix.so.dSYM
2 methods, graphics, grid, stats, utils, lattice      <NA>           <NA>
3 methods, graphics, grid, stats, utils, lattice      <NA>           <NA>
                                                         enhances os_type    priority license_is_foss
                                                            <chr>   <chr>       <chr>           <chr>
1 MatrixModels, graph, SparseM, sfsmisc, igraph, maptools, sp,...    <NA> recommended            <NA>
2 MatrixModels, graph, SparseM, sfsmisc, igraph, maptools, sp,...    <NA> recommended            <NA>
3 MatrixModels, graph, SparseM, sfsmisc, igraph, maptools, sp,...    <NA> recommended            <NA>
  license_restricts_use                repodir rversion                platform needscompilation    ref
                  <chr>                  <chr>    <chr>                   <chr>            <chr>  <chr>
1                  <NA> bin/macosx/contrib/4.2      4.2 x86_64-apple-darwin17.0             <NA> Matrix
2                  <NA>            src/contrib        *                  source              yes Matrix
3                  <NA>            src/contrib        *                  source              yes Matrix
   type direct status                                            target                       mirror
  <chr>  <lgl>  <chr>                                             <chr>                        <chr>
1  cran  FALSE     OK           bin/macosx/contrib/4.2/Matrix_1.5-0.tgz https://cloud.r-project.org/
2  cran  FALSE     OK                   src/contrib/Matrix_1.5-1.tar.gz https://cloud.r-project.org/
3  cran  FALSE     OK src/contrib/4.3.0/Recommended/Matrix_1.4-1.tar.gz https://cloud.r-project.org/
    sources filesize                                                          sha256 sysreqs built
     <list>    <dbl>                                                           <chr>   <chr> <chr>
1 <chr [2]>  5723932                                                            <NA>          <NA>
2 <chr [2]>  2200381                                                            <NA>          <NA>
3 <chr [2]>  2862737 42b24f1d1e94482b0ff0ef1292e2df29f69694bdbee47b3d6bfeec46fafb...          <NA>
            published              deps                           md5sum              path
               <dttm>            <list>                            <chr>             <chr>
1                <NA> <tbl_df [17 x 5]>                             <NA>              <NA>
2                <NA> <tbl_df [17 x 5]> e63294ce1817a8dda8a7ba7ebd9d6baa              <NA>
3 2022-03-23 16:30:08 <tbl_df [17 x 5]> 919194345873bd622e35f33655ebc1a1 4.3.0/Recommended

By modifying pkgdepends::current_config() via options(pkg.platforms = "x86_64-apple-darwin17.0"), pkgdepends::new_pkg_installation_proposal() successfully proposes the binary 1.5-0:

> getOption("pkg.platforms")
[1] "x86_64-apple-darwin17.0"
> pkgdepends::current_config()$get("platforms")
[1] "x86_64-apple-darwin17.0"
> prop = pkgdepends::new_pkg_installation_proposal("Matrix")
> prop$resolve()
> prop$get_resolution()
# pkg_resolution_result [4 x 30]
                                                              ref      type direct directpkg status
                                                            <chr>     <chr>  <lgl>     <lgl>  <chr>
1                                                          Matrix  standard   TRUE      TRUE     OK
2                                                         lattice  standard  FALSE     FALSE     OK
3 installed::/Library/Frameworks/R.framework/Resources/library... installed  FALSE      TRUE     OK
4 installed::/Library/Frameworks/R.framework/Resources/library... installed  FALSE     FALSE     OK
  package version                   license needscompilation    priority md5sum
    <chr>   <chr>                     <chr>            <lgl>       <chr>  <chr>
1  Matrix   1.5-0 GPL (>= 2) | file LICENCE            FALSE recommended   <NA>
2 lattice 0.20-45                GPL (>= 2)            FALSE recommended   <NA>
3  Matrix   1.4-1 GPL (>= 2) | file LICENCE             TRUE recommended   <NA>
4 lattice 0.20-45                GPL (>= 2)             TRUE recommended   <NA>
                                                           sha256 filesize
                                                            <chr>    <int>
1 b4c60b978a2761b440400c36075cc8b74e6fc394ea8394d0b79476adf7b2...  5246499
2 3f9344c27ac37f98cda9fa235e6a187b8bd6c4bfea228d1cd068175b7aa2...  1159260
3                                                            <NA>       NA
4                                                            <NA>       NA
                                                            built                platform rversion
                                                            <chr>                   <chr>    <chr>
1 R 4.2.0; x86_64-apple-darwin17.0; 2022-09-11 11:43:07 UTC; u... x86_64-apple-darwin17.0      4.2
2 R 4.2.0; x86_64-apple-darwin17.0; 2022-04-25 03:05:59 UTC; u... x86_64-apple-darwin17.0      4.2
3 R 4.2.1; x86_64-apple-darwin17.0; 2022-06-24 10:57:58 UTC; u... x86_64-apple-darwin17.0  R 4.2.1
4 R 4.2.1; x86_64-apple-darwin17.0; 2022-06-24 10:57:49 UTC; u... x86_64-apple-darwin17.0  R 4.2.1
  repotype                repodir                                     target              deps
     <chr>                  <chr>                                      <chr>            <list>
1     cran bin/macosx/contrib/4.2    bin/macosx/contrib/4.2/Matrix_1.5-0.tgz <tbl_df [17 x 5]>
2     cran bin/macosx/contrib/4.2 bin/macosx/contrib/4.2/lattice_0.20-45.tgz <tbl_df [10 x 5]>
3     cran            src/contrib            src/contrib/Matrix_1.4-1.tar.gz     <tbl [7 x 5]>
4     cran            src/contrib         src/contrib/lattice_0.20-45.tar.gz     <tbl [6 x 5]>
                        mirror   sources                     remote      error  metadata          extra
                         <chr>    <list>                     <list>     <list>    <list>         <list>
1 https://cloud.r-project.org/ <chr [2]>  <remote_ref_standard [6]> <list [0]> <chr [6]>     <list [0]>
2 https://cloud.r-project.org/ <chr [2]>  <remote_ref_standard [6]> <list [0]> <chr [6]>     <list [0]>
3                         <NA> <chr [0]> <remote_ref_installed [5]> <list [0]> <chr [4]> <tbl [1 x 11]>
4                         <NA> <chr [0]> <remote_ref_installed [5]> <list [0]> <chr [4]> <tbl [1 x 11]>
  dep_types    params sysreqs cache_status
     <list>    <list>   <chr>        <chr>
1 <chr [3]> <chr [0]>                 miss
2 <chr [3]> <chr [0]>                 miss
3 <chr [3]> <chr [0]>    <NA>         <NA>
4 <chr [3]> <chr [0]>    <NA>         <NA>

But pak::pkg_install() still proposes the latest source 1.5-1:

> pak::pkg_install("Matrix")
                                                                           
→ Will update 1 package.
→ Will download 1 CRAN package (2.20 MB).
+ Matrix 1.4-1 → 1.5-1 👷🏻🔧 ⬇ (2.20 MB)
? Do you want to continue (Y/n) 

I guess options(pkg.platforms = "x86_64-apple-darwin17.0") and pkgdepends::current_config() are not propagated into new sessions created by remote().

heavywatal avatar Sep 13 '22 19:09 heavywatal

Yes, at some point this will be fixed and we'll propagate all options, but for now you'll need to set the corresponding env vars, before you load pak.

gaborcsardi avatar Sep 13 '22 20:09 gaborcsardi

Confirmed that setting PKG_PLATFORMS works as expected (and loading pkgdepends before setting the env var is allowed). Thank you for your prompt reply!

> Sys.setenv(PKG_PLATFORMS = pkgdepends::current_r_platform())
> Sys.getenv("PKG_PLATFORMS")
[1] "x86_64-apple-darwin17.0"
> pak::pkg_install("Matrix")
✔ Loading metadata database ... done
                                                                           
→ Will update 1 package.
→ Will download 1 CRAN package (5.25 MB).
+ Matrix 1.4-1 → 1.5-0  ⬇ (5.25 MB)
? Do you want to continue (Y/n)

heavywatal avatar Sep 14 '22 00:09 heavywatal

Just to clarify, pkgdepends is not relevant here (other than you are using it to get the current platform), because pak has its own copy of it from its own library.

gaborcsardi avatar Sep 14 '22 10:09 gaborcsardi

Thanks for the clarification. I also realized that pkgdepends::current_r_platform() is overkill in this context because it is equivalent to R.version$platform on non-Linux systems. Now I'm satisfied with the following code in my .Rprofile:

if (endsWith(.Platform$pkgType, "binary")) {
  Sys.setenv(PKG_PLATFORMS = R.version$platform)
}

heavywatal avatar Sep 14 '22 11:09 heavywatal

Btw. I think you can also set the platform to macos or windows, and we should probably support binary as well.

Btw. 2. you might know this already, but if you only allow binary packages, then pak might fail if some packages do not have binaries available.

gaborcsardi avatar Sep 14 '22 11:09 gaborcsardi

Options are now copied to the subprocess.

gaborcsardi avatar Nov 01 '23 13:11 gaborcsardi