rstudio / renv

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

renv github dependencies don't work with rsconnect::deployApp #308

Closed shanebdavis closed 4 years ago

shanebdavis commented 4 years ago

I have a large existing application I am converting to using Renv. Mostly it's gone great, but there are a couple of direct github dependencies. Locally, it's no problem. Renv installs and restores them fine. However, when I attempt to deploy with rsconnect::deployApp, they fail.

I created a simple repo to demo the problem with full documentation:

In short, I have a tiny app which deploys, but when I run the following:

renv::install("th86/concordanceIndex”)

And starting using the library in the source (e.g. concordanceIndex::concordanceIndex), the deploy fails:

> rsconnect::deployApp()
Preparing to deploy application...
Update application currently deployed at
https://iatlas-test.shinyapps.io/084-single-file/? [Y/n] y
DONE
Uploading bundle for application: 1597446...Warning in FUN(X[[i]], ...) :
  Unable to find repository URL for package concordanceIndex
DONE
Deploying bundle: 2688358 for application: 1597446 ...
Waiting for task: 678405041
  building: Building image: 2935776
  building: Building package: concordanceIndex
################################ Begin Task Log ################################ 
################################# End Task Log ################################# 
Error: Unhandled Exception: Child Task 678405042 failed: Error building image: Error fetching concordanceIndex (0.1) source. <CRANPackageSource repo='http://cran.rstudio.org'> unable to satisfy package: concordanceIndex (0.1)
In addition: Warning message:
In FUN(X[[i]], ...) :
  Package 'concordanceIndex 0.1' was installed from sources; Packrat will assume this package is available from a CRAN-like repository during future restores

Versions:

I have a workaround at the moment from the doc on this page: https://docs.rstudio.com/shinyapps.io/getting-started.html

renv::install('devtools')
devtools::install_github("th86/concordanceIndex", force=TRUE)

However, whatever devtools::install_github does isn't reflected in changes in my repository. Every time someone checks out my repository, they have to manually run devtools::install_github for every github dependency.

The original renv::install + renv::snapshot should be all I need to use a github dependency, right?

kevinushey commented 4 years ago

Does this work if you install the development version of Packrat?

shanebdavis commented 4 years ago

Does this work if you install the development version of Packrat?

I don't think so. Here's what I tried:

git clone git@github.com:generalui/renv-rsconnect-github.git
cd renv-rsconnect-github
open renv-rsconnect-github.Rproj

Then in RStudio:

renv::restore(confirm=FALSE)
install.packages("devtools")
devtools::install_github("rstudio/packrat")
rsconnect::deployApp()
# fails in a NEW way: GithubUsername must be specified for GitHub package source

If I do the steps exactly as I've just specified. I get a new error. Here is the full listing of the new error:

Preparing to deploy application...DONE
Uploading bundle for application: 1631275...DONE
Deploying bundle: 2710316 for application: 1631275 ...
Waiting for task: 680910253
  error: Parsing manifest
################################ Begin Task Log ################################ 
################################# End Task Log ################################# 
Error: Unhandled Exception: Child Task 680910254 failed: Error parsing manifest: GithubUsername must be specified for GitHub package source

HOWEVER, if I do things in a slightly different order, as show below, I get the error I originally mentioned:

Start with a fresh git clone as per the steps above, then in RStudio:

renv::restore(confirm=FALSE)
rsconnect::deployApp()
# fails in the old way: unable to satisfy package: concordanceIndex (0.1)

install.packages("devtools")
devtools::install_github("rstudio/packrat")
rsconnect::deployApp()
# fails in the old way: unable to satisfy package: concordanceIndex (0.1)

Versions:

kevinushey commented 4 years ago

I've made some changes to the development version of renv that should help ensure backwards compatibility with the existing deployment workflows. Can you try updating renv and reinstalling any packages which are giving you trouble during deploy, and let me know if it helps?

shanebdavis commented 4 years ago

Thanks for the quick patch! I updated to 0.9.2-14. Unfortunately, it didn't seem to work.

However, I think I have an insight into what is going on. I inspected the DESCRIPTION file for concodanceIndex in renv/library both before and after I ran devtools::install_github("th86/concordanceIndex", force=TRUE). As specified above, it works after I do a devtools::install_github, but not before.

Here is the DESCRIPTION file as installed by renv:

Package: concordanceIndex
Version: 0.1
Date: 2017
Title: Concordance Index
Author: Tai-Hsien, Ou Yang <to2232@columbia.edu>
Depends: R (>= 3.3.1)
Description: Evaluating the concordance index of a feature and the corresponding censored survival
Archs: i386, x64
RoxygenNote: 6.1.1.9000
Built: R 3.6.2; x86_64-apple-darwin19.2.0; 2020-01-06 20:19:45 UTC; unix
RemoteType: github
RemoteRepo: concordanceIndex
RemoteUsername: th86
RemoteRef: master
RemoteSha: 2e6f75f9c85c509e021e374a83ca58478e88e2dc
RemoteHost: api.github.com
RemoteRepo.1: concordanceIndex
RemoteUsername.1: th86
RemoteRef.1: master
RemoteSha.1: 2e6f75f9c85c509e021e374a83ca58478e88e2dc

And here is the DESCRIPTION file as installed by devtools::install_github:

Package: concordanceIndex
Version: 0.1
Date: 2017
Title: Concordance Index
Author: Tai-Hsien, Ou Yang <to2232@columbia.edu>
Depends: R (>= 3.3.1)
Description: Evaluating the concordance index of a feature and the corresponding censored survival
Archs: i386, x64
RoxygenNote: 6.1.1.9000
RemoteType: github
RemoteHost: api.github.com
RemoteRepo: concordanceIndex
RemoteUsername: th86
RemoteRef: master
RemoteSha: 2e6f75f9c85c509e021e374a83ca58478e88e2dc
GithubRepo: concordanceIndex
GithubUsername: th86
GithubRef: master
GithubSHA1: 2e6f75f9c85c509e021e374a83ca58478e88e2dc
NeedsCompilation: yes
Packaged: 2020-01-07 00:26:27 UTC; shanebdavis
Built: R 3.6.2; x86_64-apple-darwin19.2.0; 2020-01-07 00:26:27 UTC; unix

On a hunch, I restored everything to the pure-renv solution (git cloned a fresh directory, then renv::restore). THEN, I edited the installed concordanceIndex's DESCRIPTION and added the four missing fields that started with Github*. Then I ran rsconnect::deployApp - it worked!!!

It seems rsconnect requires those Github entries...

shanebdavis commented 4 years ago

AND... I think that's what you just fixed. I just realized I had to clear my RENV cache for it to work properly. When I did, and then did a renv::restore, it added toe Github fields. Awesome!

Thanks so much for the fix!

mohang13 commented 4 years ago

Hi @shanebdavis, I'm facing a similar issue, I have migrated from packrat. I can deploy with packrat without any error but with renv I'm getting a similar error you mentioned above. Can you explain how you solved it?

KarimZaoui commented 3 years ago

@mohang13 did you find a solution?