rstudio / renv

renv: Project environments for R.
https://rstudio.github.io/renv/
MIT License
1k stars 152 forks source link

Add mechanism to force installation via GitHub API rather than git clone method #1097

Open gadenbuie opened 1 year ago

gadenbuie commented 1 year ago

In work to fix #1075, packages installed from GitHub that contain submodules now use git rather than the GitHub remote types. This might be necessary if the submodule is part of the package source, but it isn't always required and may cause downstream issues with deploying content to Connect that depends on packages installed with these methods.

I've set up a reprex repo at gadenbuie/renv-git-submodules. In that repo, using hadley/emo installed via renv confuses rsconnect::writeManifest().

str(renv:::renv_json_read("renv.lock")$Packages$emo)
## List of 12
##  $ Package       : chr "emo"
##  $ Version       : chr "0.0.0.9000"
##  $ Source        : chr "git"
##  $ RemoteType    : chr "git"
##  $ RemoteUrl     : chr "https://github.com/hadley/emo"
##  $ RemoteHost    : chr "api.github.com"
##  $ RemoteUsername: chr "hadley"
##  $ RemoteRepo    : chr "emo"
##  $ RemoteRef     : chr "3f03b11491ce3d6fc5601e210927eff73bf8e350"
##  $ RemoteSha     : chr "3f03b11491ce3d6fc5601e210927eff73bf8e350"
##  $ Hash          : chr "38cd5a58901f1ba87ca769667d557a76"
##  $ Requirements  :List of 8
##   ..$ : chr "assertthat"
##   ..$ : chr "crayon"
##   ..$ : chr "glue"
##   ..$ : chr "lubridate"
##   ..$ : chr "magrittr"
##   ..$ : chr "purrr"
##   ..$ : chr "rlang"
##   ..$ : chr "stringr"

The problem that arises is that I can’t deploy content that uses emo installed with renv 0.16.0 to Connect because rsconnect::writeManifest() can’t determine the repository URL.

rsconnect::writeManifest(appPrimaryDoc = "example.Rmd")
## Warning in FUN(X[[i]], ...): Package 'emo 0.0.0.9000' was installed from
## sources; Packrat will assume this package is available from a CRAN-like
## repository during future restores

## Warning: 
## * May be unable to deploy package dependency 'emo'; could not determine
##   a repository URL for the source 'CRAN'.
## 
## * Unable to determine the source location for some packages. Packages
##   should be installed from a package repository like CRAN or a version
##   control system. Check that options('repos') refers to a package
##   repository containing the needed package versions.

While it's probably worth raising this issue with rsconnect, I still feel that renv should provide a mechanism for overriding this choice, perhaps if installing with an explicit github:: prefix?

kevinushey commented 1 year ago

Obviously not the greatest of workarounds, but ...

> original <- renv:::renv_binding_replace(
+   "renv_remotes_resolve_github_modules",
+   function(...) FALSE,
+   envir = asNamespace("renv")
+ )
> 
> renv::install("hadley/emo", rebuild = TRUE)
Retrieving 'https://api.github.com/repos/hadley/emo/tarball/3f03b11491ce3d6fc5601e210927eff73bf8e350' ...
    OK [downloaded 197.4 Kb in 0.4 secs]
Installing emo [0.0.0.9000] ...
    OK [built from source]
Copying emo [0.0.0.9000] into the cache ...
    OK [copied to cache in 28 milliseconds]
> packageDescription("emo")
Package: emo
Title: Easily Insert 'Emoji'
Version: 0.0.0.9000
Authors@R: c( person("Hadley", "Wickham", , "hadley@rstudio.com", role = c("aut", "cre")), person("Romain",
            "François", , "romain@thinkr.fr", role = c("aut")), person("Lucy", "D'Agostino McGowan", email
            = "ld.mcgowan@vanderbilt.edu", role = c("aut")), person("RStudio", role = "cph") )
Description: Makes it easy to insert 'emoji' based on either their name or a descriptive keyword.
Depends: R (>= 2.10)
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports: stringr, glue (>= 1.3.0), crayon, utils, magrittr, assertthat, lubridate, rlang, purrr
RoxygenNote: 6.0.1.9000
URL: https://github.com/hadley/emo
BugReports: https://github.com/hadley/emo/issues
Suggests: testthat, dplyr
Author: Hadley Wickham [aut, cre], Romain François [aut], Lucy D'Agostino McGowan [aut], RStudio [cph]
Maintainer: Hadley Wickham <hadley@rstudio.com>
Built: R 4.2.1; ; 2022-10-18 21:38:08 UTC; unix
RemoteType: github
RemoteHost: api.github.com
RemoteUsername: hadley
RemoteRepo: emo
RemoteRef: master
RemoteSha: 3f03b11491ce3d6fc5601e210927eff73bf8e350
GithubHost: api.github.com
GithubRepo: emo
GithubUsername: hadley
GithubRef: master
GithubSHA1: 3f03b11491ce3d6fc5601e210927eff73bf8e350

-- File: /Users/kevin/Library/R/arm64/4.2/library/emo/Meta/package.rds