Problem installing suggested remote dependency (Remote section is "ignored")

I am trying to add a remote GitHub suggested dependency (openxlsx2) in the rempsyc package, as such (rempsyc/DESCRIPTION at main · rempsyc/rempsyc · GitHub):

Suggests: 
    [...]
    remotes,
    openxlsx2,
Remotes: 
    github::JanMarvin/openxlsx2

But when attempting to document/install locally (after manually uninstalling openxlsx2 to test it) I get

Warning in (function (dep_name, dep_ver = "*")  :
  Dependency package 'openxlsx2' not available.
Error in `abort_for_missing_packages()`:
! Dependency package(s) 'openxlsx2' not available.

The command to install the package is remotes::install_github("JanMarvin/openxlsx2") and it's GitHub can be retrieved from GitHub - JanMarvin/openxlsx2: openxlsx2 - read, write and modify xlsx files. It seems that the Remotes section is being ignored and that it is trying to install the dependency from CRAN and thus fails.

I have tried other remote packages with the same result, and also changing from Suggests: to Imports:, and removing the optional github:: bit, with no success so far, so it seems a problem with my own setup. So I have updated all my packages and restarted my computer, RStudio, and R. And now, I am getting this message on start-up:

Error in .rs.parsePackageDependencies(contents, extension) : 
  object 'partition_yaml_front_matter' not found

When I pushed the change to GitHub to see if it was a local problem and GitHub would run directly, there was an error (on Windows only: R-CMD-check · rempsyc/rempsyc@9e147ff · GitHub):

C:\rtools40\usr\bin\tar.exe --use-compress-program "zstd -d" -xf D:/a/_temp/a1c2b5ca-dcde-4da8-9a76-7dcea8572bd6/cache.tzst -P -C D:/a/rempsyc/rempsyc --force-local

 ! rlang, fansi, utf8, and vctrs are loaded in other R sessions and have locked
  files in your library. The installation will probably fail, unless you quit
  from this R session:
  
  • Rterm.exe (5876) in cmd.exe (6908)

 ℹ Building openxlsx2 0.2.1.9000
  ✖ Failed to build openxlsx2 0.2.1.9000
  
  Error: Error: <callr_remote_error: Failed to build source package 'openxlsx2'>
   in process 5876 
  -->
  Failed to build source package 'openxlsx2', stdout + stderr:

  OE> * installing *source* package 'openxlsx2' ...

 OE> Error: package or namespace load failed for 'openxlsx2' in inDL(x, as.logical(local), as.logical(now), ...):
  OE>  unable to load shared object 'C:/Users/runneradmin/AppData/Local/Temp/RtmpIn5JEg/pkg-lib16f464242299/openxlsx2/libs/x64/openxlsx2.dll':
  OE>   LoadLibrary failure:  The specified procedure could not be found.
  OE> 
  OE> Error: loading failed
  OE> Execution halted
  OE> ERROR: loading failed
  OE> * removing 'C:/Users/RUNNER~1/AppData/Local/Temp/RtmpIn5JEg/pkg-lib16f464242299/openxlsx2'

When I install the package manually and do the checks everything works fine, but I just want to test that the remote install works well for users that will not have the package installed and I cannot make it work so I am afraid that others too won't be able to install it remotely.

In my function, I have the following check:

rlang::check_installed("openxlsx2", reason = "for this function.")

So I try running the function without that package installed to see if it will install it correctly, but here is what I get:

cormatrix_excel2(mtcars)
ℹ The package `openxlsx2` is required for this function.
✖ Would you like to install it?

1: Yes
2: No

Selection: 1
Installing package into ‘D:/Rpackages’
(as ‘lib’ is unspecified)

Error in loadNamespace(x) : there is no package called ‘openxlsx2’
In addition: Warning message:
package ‘openxlsx2’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html

I am not sure what to do and I keep searching online but do not find solutions that work or with my exact problem. Any idea?

At this point I'm wondering whether I need to do a manual workaround like checking if the package is installed (with require) and install it from GitHub from the function directly if it's not installed? I know this is not good practice but the other things I've tried are not working so far.

In the meanwhile, this is the manual solution I came up with (added at the beginning of the offending function):

if (isFALSE(requireNamespace(openxlsx2, quietly = TRUE))) {
  rlang::check_installed(
    "remotes",
    reason = "to install the required dependency for this function (openxlsx2)."
  )
  cat("The package `openxlsx2` is required for this function\n",
      "Would you like to install it?")
  if (utils::menu(c("Yes", "No")) == 1) {
    remotes::install_github('JanMarvin/openxlsx2')
  } else (stop(
    "The cormatrix_excel2 function relies on the `openxlsx2` package.
    You can install it manually with:
    remotes::install_github('JanMarvin/openxlsx2')"))
  }

Not good practice, but at least it works!

What do you mean by that? You run devtools::document()? Or install.packages()? These will not install any dependencies.

Being ignored by which function exactly?

Thanks for your answer Gabor!

What do you mean by that? You run devtools::document()? Or install.packages()? These will not install any dependencies.

Yes I was trying to document and install with the RStudio Ctrl+Shift+D and Ctr+Shift+B shortcuts. So I understand that this is normal and that you can't document or install if you don't have the package installed on your machine (thus the error is expected). Good to know!

I was trying to test the external remote GitHub dependency install, and normally, you don't have the dependency when you install the package so... how are you supposed to test this?

Being ignored by which function exactly?

By Ctr+Shift+B. To try something different, I just uninstalled openxlsx2 and my own rempsyc package and tried reinstalling rempsyc from GitHub in its current version. The install worked, but when I tried the offending function, I get this message:

Error in loadNamespace(x) : there is no package called ‘openxlsx2’
In addition: Warning message:
package ‘openxlsx2’ is not available for this version of R

I wonder if it is because it calls:

 rlang::check_installed("openxlsx2", reason = "for this function.")

So I mean ignored by rlang::check_installed. Is it because rlang::check_installed can only install from CRAN? I thought it would read from the DESCRIPTION to get the remote install instructions.

I am not entirely sure what you mean here. Do you want to write a test case in tests that tests that remotes::install_github() can install your dependency from GitHub? Probably not....

Indeed, that does not install any dependencies, not just the ones in Remotes, but it also does not install "regular" imported packages from CRAN. It just runs R CMD build or pkgbuild::build().

What exactly did you run? remotes::install_github()? Did you restart R after uninstalling the packages?

This is a separate thing again. rlang::check_installed() cannot look in the DESCRIPTION file of the package, because it does not even know which package is was called from. It will only install packages from the configured repositories, i.e. getOption("repos").

Thank you for this additional information and reply.

Indeed, I was not trying to write an actual "test", but just to see if users are actually able to make the function (which relies on the remote dependency) work. It seems the actual reason it was not working is indeed due to rlang::check_installed, thus my added confusion with my other failed attempts. Thank you for clarifying these aspects.

I first uninstalled both packages with the RStudio "Packages" menu, then reinstalled rempsyc from the console with devtools::install_github("rempsyc/rempsyc"). And restarted R, yes. But it seems the real problem was using rlang::check_installed, so my manual check-install in my second answer should be the right way to go about it (check whether the package is installed, and if not, ask the user whether they want to install it, and if yes, install it from GitHub directly). Again, thank you for clarifying these elements.

I suppose this brings us then to the last point. It seems that from the GitHub actions, openxlsx2 is indeed detected as Suggested package and so there is an attempt to install it. However, it fails—on Windows only. I wonder if you would have any idea about why this would be the case and if there's anything I could do about it? It is strange because I am on Windows and not experiencing any error when running R CMD check locally. I am quoting the error here again for convenience:

This is the only thing preventing my package to have no errors and warnings during GitHub actions. Thank you.

Here is an update: the author of the openxlsx2 package has added the package to the r-universe, therefore the package can be downloaded without remotes, as such:

install.packages('openxlsx2', repos = "https://janmarvin.r-universe.dev")

Can I now do something like this?

Suggests: 
    [...]
    remotes,
    openxlsx2,
Remotes: 
    r-universe::JanMarvin/openxlsx2

Or else, how would I specify that the dependency relies on the r-universe? I feel like this should solve the problem as it will avoid rebuilding the package (it installs really quickly without having to rebuild).

I am not sure why that package fails to install. Maybe the maintainer has some ideas. FWIW their very similar looking workflow seems to work fine: Merge pull request #297 from JanMarvin/fix-remove_worksheet · JanMarvin/openxlsx2@b40cf30 · GitHub

Thanks. The maintainer is not sure, understandably, as, as you point out, his own GitHub workflow doesn't fail (and the r-universe flow also doesn't fail). So it's a really weird error, but I don't know enough about this to comment intelligently. What I've tried though, upon the maintainer's suggestion, is to add the following to the GitHub action R-CMD-check.yaml workflow directly instead of attempting to specify a version thereof in the DESCRIPTION file:

options(repos = c(
  janmarvin = 'https://janmarvin.r-universe.dev',
  CRAN = 'https://cloud.r-project.org'))

Which works when run locally on my console. So I've added the following between two other actions/steps: rempsyc/R-CMD-check.yaml at main · rempsyc/rempsyc · GitHub

- uses: r-lib/actions/setup-r@v2
[...]

- name: Define repo options
  run: options(repos = c(
     janmarvin = "https://janmarvin.r-universe.dev",
     CRAN = "https://cloud.r-project.org"))
  shell: Rscript {0}

- uses: r-lib/actions/setup-r-dependencies@v2
[...]

The repo setting step seems to work: R-CMD-check · rempsyc/rempsyc@2ac61ce · GitHub

Run options(repos = c( janmarvin = "https://janmarvin.r-universe.dev", CRAN = "https://cloud.r-project.org"))
  options(repos = c( janmarvin = "https://janmarvin.r-universe.dev", CRAN = "https://cloud.r-project.org"))
  shell: C:\R\bin\Rscript.EXE {0}
  env:
    GITHUB_PAT: ***
    R_KEEP_PKG_SOURCE: yes
    R_LIBS_USER: D:\a\_temp\Library
    TZ: UTC
    _R_CHECK_SYSTEM_CLOCK_: FALSE
    NOT_CRAN: true
    RSPM: https://packagemanager.rstudio.com/all/latest

But not the install step:

  Error: Error: <callr_remote_error: Cannot install packages:
  * deps::.: Can't install dependency openxlsx2
  * openxlsx2: Can't find package called openxlsx2.>

Any idea why?

Ok I think I figured something out: it seems not to matter to define repo options in an earlier step because r-lib/actions/setup-r-dependencies@v2 overwrites that with:

install.packages("pak", repos = "https://r-lib.github.io/p/pak/stable/")

So if there is a way to modify r-lib/actions/setup-r-dependencies@v2, then perhaps I would be able to overwrite that line with the following?

install.packages("pak", repos = c("https://r-lib.github.io/p/pak/stable/", "https://janmarvin.r-universe.dev"))

CONFIRMED solution:

actions/setup-r-dependencies at v2 · r-lib/actions · GitHub

Dependencies in other CRAN-like repositories

If your dependency is available in a CRAN-like repository (e.g. R-universe), then you can use the extra-repositories parameter of the setup-r action. See more at the setup-r documentation.

So I had to add the extra-repositories: "https://janmarvin.r-universe.dev" line after with in the - uses: r-lib/actions/setup-r@v2 line, so it looks like this in the R-CMD-check.yaml workflow file:

  - uses: r-lib/actions/setup-r@v2
    with:
      r-version: ${{ matrix.config.r }}
      http-user-agent: ${{ matrix.config.http-user-agent }}
      use-public-rspm: true
      extra-repositories: "https://janmarvin.r-universe.dev"
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.