如何解决使用renv与协作者共享代码时安装依赖项的问题?

问题描述 投票:0回答:1

我有一些使用R编程语言编写的脚本,为了让我的朋友在自己的机器上运行这些脚本没有任何问题,并且他们可以获得与我相同的环境变量,我与他们共享了renv.lock,.Rprofile,和 renv/activate.R 文件。

但是,他们在将依赖项安装到电脑中时面临一些问题。他们首先将工作目录设置为特定的项目文件夹,然后分别运行以下命令:

renv::restore()
renv::install()

这样做时他们收到以下错误:

renv::restore()
It looks like you've called renv::restore() in a project that hasn't been activated yet.
How would you like to proceed?

1: Activate the project and use the project library.
2: Do not activate the project and use the current library paths.
3: Cancel and resolve the situation another way.

Selection: 1

Restarting R session...

- Project 'C:/Users/Lenovo/Desktop/RProjects/the_app' loaded. [renv 1.0.3]
- None of the packages recorded in the lockfile are currently installed.
> renv::install()
- Unrecognized response: please enter 'y' or 'n', or type Ctrl + C to cancel.
- Would you like to restore the project library? [y/N]: y

The following package(s) will be updated:

# CRAN -----------------------------------------------------------------------
- base64enc        [* -> 0.1-3]
- bslib            [* -> 0.5.1]
- cachem           [* -> 1.0.8]
- cli              [* -> 3.6.1]
- commonmark       [* -> 1.9.0]
- crayon           [* -> 1.5.2]
- digest           [* -> 0.6.33]
- ellipsis         [* -> 0.3.2]
- fastmap          [* -> 1.1.1]
- fontawesome      [* -> 0.5.2]
- fresh            [* -> 0.2.0]
- fs               [* -> 1.6.3]
- glue             [* -> 1.6.2]
- gridExtra        [* -> 2.3]
- gtable           [* -> 0.3.4]
- htmltools        [* -> 0.5.6.1]
- httpuv           [* -> 1.6.11]
- jquerylib        [* -> 0.1.4]
- jsonlite         [* -> 1.8.7]
- later            [* -> 1.3.1]
- lifecycle        [* -> 1.0.3]
- magrittr         [* -> 2.0.3]
- memoise          [* -> 2.0.1]
- mime             [* -> 0.12]
- png              [* -> 0.1-8]
- promises         [* -> 1.2.1]
- R6               [* -> 2.5.1]
- rappdirs         [* -> 0.3.3]
- Rcpp             [* -> 1.0.11]
- rlang            [* -> 1.1.1]
- rstudioapi       [* -> 0.15.0]
- sass             [* -> 0.4.7]
- shiny            [* -> 1.7.5]
- shinydashboard   [* -> 0.7.2]
- sourcetools      [* -> 0.1.7-1]
- withr            [* -> 2.5.1]
- xtable           [* -> 1.8-4]

# Downloading packages -------------------------------------------------------
- Querying repositories for available binary packages ... Done!
renv was unable to query available packages from the following repositories:
- # https://packagemanager.posit.co/cran/latest/bin/windows/contrib/4.3 --------
error downloading 'https://packagemanager.posit.co/cran/latest/bin/windows/contrib/4.3/PACKAGES.rds' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]
error downloading 'https://packagemanager.posit.co/cran/latest/bin/windows/contrib/4.3/PACKAGES.gz' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]
error downloading 'https://packagemanager.posit.co/cran/latest/bin/windows/contrib/4.3/PACKAGES' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]


- Querying repositories for available source packages ... Done!
renv was unable to query available packages from the following repositories:
- # https://packagemanager.posit.co/cran/latest/src/contrib --------------------
error downloading 'https://packagemanager.posit.co/cran/latest/src/contrib/PACKAGES.rds' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]
error downloading 'https://packagemanager.posit.co/cran/latest/src/contrib/PACKAGES.gz' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]
error downloading 'https://packagemanager.posit.co/cran/latest/src/contrib/PACKAGES' [curl: (35) schannel: next InitializeSecurityContext failed: Unknown error (0x80092012) - The revocation function was unable to check revocation for the certificate.]


Warning: failed to find binary for 'htmltools 0.5.6.1' in package repositories
Warning: failed to find source for 'htmltools 0.5.6.1' in package repositories
Error: failed to retrieve package '[email protected]'
Traceback (most recent calls last):
31: source("renv/activate.R")
30: withVisible(eval(ei, envir))
29: eval(ei, envir)
28: eval(ei, envir)
27: local(...) at activate.R#2
26: eval.parent(substitute(eval(quote(expr), envir)))
25: eval(expr, p)
24: eval(expr, p)
23: eval(quote(...), new.env())
22: eval(quote(...), new.env())
21: renv_bootstrap_exec(project, libpath, version) at activate.R#1176
20: if (!renv_bootstrap_load(project, libpath, version))
      renv_bootstrap_run(version, libpath) at activate.R#1009
19: renv::load(project) at activate.R#864
18: renv_load_finish(project, lockfile)
17: renv_load_report_synchronized(project, lockfile)
16: restore(project, prompt = FALSE, exclude = "renv")
15: renv_restore_run_actions(project, diff, current, lockfile, rebuild)
14: retrieve(packages)
13: handler(package, renv_retrieve_impl(package))
12: renv_retrieve_impl(package)
11: renv_retrieve_successful(record, path)
10: (function() {
        repos <- if (is.null(desc$biocViews))
            getOption("repos")
        else renv_bioconductor_repos()
        renv_scope_options(repos = repos)
        renv_retrieve_successful_recurse(deps)
    })()
 9: renv_retrieve_successful_recurse(deps)
 8: renv_retrieve_successful_recurse_impl(remote)
 7: dynamic(key = list(remote = remote), value = renv_retrieve_successful_recurse_impl_one(remote))
 6: the$dynamic_objects[[id]] %||% {
        dlog("dynamic", "memoizing dynamic value for '%s'", id)
        value
    }
 5: renv_retrieve_successful_recurse_impl_one(remote)
 4: renv_retrieve_impl(remote)
 3: renv_retrieve_repos(record)
 2: stopf("failed to retrieve package '%s'", renv_record_format_remote(record))
 1: stop(sprintf(fmt, ...), call. = call.)

然后他们运行

renv::diagnostics()
命令,得到的结果如下:

> renv::diagnostics()
Diagnostics Report [renv 1.0.3]
===============================

# Session Info ---------------------------------------------------------------
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default


locale:
[1] LC_COLLATE=English_United Kingdom.utf8
[2] LC_CTYPE=English_United Kingdom.utf8 
[3] LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C                         
[5] LC_TIME=English_United Kingdom.utf8   

time zone: Europe/London
tzcode source: internal

attached base packages:
[1] stats     graphics  datasets  grDevices utils     methods   base   

loaded via a namespace (and not attached):
[1] compiler_4.3.1 tools_4.3.1    renv_1.0.3   

# Project --------------------------------------------------------------------
Project path: "C:/Users/Lenovo/Desktop/RProjects/the_app"

# Status ---------------------------------------------------------------------
The following package(s) are missing:

 package        installed recorded used
 base64enc      n         y        ? 
 bslib          n         y        ? 
 cachem         n         y        ? 
 cli            n         y        ? 
 commonmark     n         y        ? 
 crayon         n         y        ? 
 digest         n         y        ? 
 ellipsis       n         y        ? 
 fastmap        n         y        ? 
 fontawesome    n         y        ? 
 fresh          n         y        y 
 fs             n         y        ? 
 glue           n         y        ? 
 gridExtra      n         y        y 
 gtable         n         y        ? 
 htmltools      n         y        ? 
 httpuv         n         y        ? 
 jquerylib      n         y        ? 
 jsonlite       n         y        y 
 later          n         y        ? 
 lifecycle      n         y        ? 
 magrittr       n         y        ? 
 memoise        n         y        ? 
 mime           n         y        ? 
 png            n         y        y 
 promises       n         y        ? 
 R6             n         y        ? 
 rappdirs       n         y        ? 
 Rcpp           n         y        ? 
 rlang          n         y        ? 
 rstudioapi     n         y        ? 
 sass           n         y        ? 
 shiny          n         y        y 
 shinydashboard n         y        y 
 sourcetools    n         y        ? 
 withr          n         y        ? 
 xtable         n         y        ? 

See ?renv::status() for advice on resolving these issues.

# Packages -------------------------------------------------------------------
                Library Source Lockfile Source Path Dependency
KernSmooth      2.23-21   CRAN     <NA>   <NA>  [2]       <NA>
MASS             7.3-60   CRAN     <NA>   <NA>  [2]       <NA>
Matrix          1.5-4.1   CRAN     <NA>   <NA>  [2]       <NA>
R6                 <NA>   <NA>    2.5.1   CRAN <NA>       <NA>
Rcpp               <NA>   <NA>   1.0.11   CRAN <NA>       <NA>
base               <NA>   <NA>     <NA>   <NA>  [2]     direct
base64enc          <NA>   <NA>    0.1-3   CRAN <NA>       <NA>
boot           1.3-28.1   CRAN     <NA>   <NA>  [2]       <NA>
bslib              <NA>   <NA>    0.5.1   CRAN <NA>       <NA>
cachem             <NA>   <NA>    1.0.8   CRAN <NA>       <NA>
class            7.3-22   CRAN     <NA>   <NA>  [2]       <NA>
cli                <NA>   <NA>    3.6.1   CRAN <NA>       <NA>
cluster           2.1.4   CRAN     <NA>   <NA>  [2]       <NA>
codetools        0.2-19   CRAN     <NA>   <NA>  [2]       <NA>
commonmark         <NA>   <NA>    1.9.0   CRAN <NA>       <NA>
crayon             <NA>   <NA>    1.5.2   CRAN <NA>       <NA>
digest             <NA>   <NA>   0.6.33   CRAN <NA>       <NA>
ellipsis           <NA>   <NA>    0.3.2   CRAN <NA>       <NA>
fastmap            <NA>   <NA>    1.1.1   CRAN <NA>       <NA>
fontawesome        <NA>   <NA>    0.5.2   CRAN <NA>       <NA>
foreign          0.8-84   CRAN     <NA>   <NA>  [2]       <NA>
fresh              <NA>   <NA>    0.2.0   CRAN <NA>     direct
fs                 <NA>   <NA>    1.6.3   CRAN <NA>       <NA>
glue               <NA>   <NA>    1.6.2   CRAN <NA>       <NA>
grDevices          <NA>   <NA>     <NA>   <NA>  [2]   indirect
grid               <NA>   <NA>     <NA>   <NA>  [2]     direct
gridExtra          <NA>   <NA>      2.3   CRAN <NA>     direct
gtable             <NA>   <NA>    0.3.4   CRAN <NA>       <NA>
htmltools          <NA>   <NA>  0.5.6.1   CRAN <NA>       <NA>
httpuv             <NA>   <NA>   1.6.11   CRAN <NA>       <NA>
jquerylib          <NA>   <NA>    0.1.4   CRAN <NA>       <NA>
jsonlite           <NA>   <NA>    1.8.7   CRAN <NA>     direct
later              <NA>   <NA>    1.3.1   CRAN <NA>       <NA>
lattice          0.21-8   CRAN     <NA>   <NA>  [2]       <NA>
lifecycle          <NA>   <NA>    1.0.3   CRAN <NA>       <NA>
magrittr           <NA>   <NA>    2.0.3   CRAN <NA>       <NA>
memoise            <NA>   <NA>    2.0.1   CRAN <NA>       <NA>
mgcv             1.8-42   CRAN     <NA>   <NA>  [2]       <NA>
mime               <NA>   <NA>     0.12   CRAN <NA>       <NA>
nlme            3.1-162   CRAN     <NA>   <NA>  [2]       <NA>
nnet             7.3-19   CRAN     <NA>   <NA>  [2]       <NA>
png                <NA>   <NA>    0.1-8   CRAN <NA>     direct
promises           <NA>   <NA>    1.2.1   CRAN <NA>       <NA>
rappdirs           <NA>   <NA>    0.3.3   CRAN <NA>       <NA>
renv              1.0.3   CRAN    1.0.3   CRAN  [1]     direct
rlang              <NA>   <NA>    1.1.1   CRAN <NA>       <NA>
rpart            4.1.19   CRAN     <NA>   <NA>  [2]       <NA>
rstudioapi         <NA>   <NA>   0.15.0   CRAN <NA>       <NA>
sass               <NA>   <NA>    0.4.7   CRAN <NA>       <NA>
shiny              <NA>   <NA>    1.7.5   CRAN <NA>     direct
shinydashboard     <NA>   <NA>    0.7.2   CRAN <NA>     direct
sourcetools        <NA>   <NA>  0.1.7-1   CRAN <NA>       <NA>
spatial          7.3-16   CRAN     <NA>   <NA>  [2]       <NA>
survival          3.5-5   CRAN     <NA>   <NA>  [2]       <NA>
tools              <NA>   <NA>     <NA>   <NA>  [2]     direct
utils              <NA>   <NA>     <NA>   <NA>  [2]     direct
withr              <NA>   <NA>    2.5.1   CRAN <NA>       <NA>
xtable             <NA>   <NA>    1.8-4   CRAN <NA>       <NA>

[1]: C:/Users/Lenovo/Desktop/RProjects/the_app/renv/library/R-4.3/x86_64-w64-mingw32       
[2]: C:/Users/Lenovo/AppData/Local/R/cache/R/renv/sandbox/R-4.3/x86_64-w64-mingw32/bd3f13aa

# ABI ------------------------------------------------------------------------
- ABI conflict checks are not yet implemented on Windows.

# User Profile ---------------------------------------------------------------
[no user profile detected]

# Settings -------------------------------------------------------------------
List of 13
 $ bioconductor.version     : NULL
 $ external.libraries       : chr(0)
 $ ignored.packages         : chr(0)
 $ package.dependency.fields: chr [1:3] "Imports" "Depends" "LinkingTo"
 $ ppm.enabled              : NULL
 $ ppm.ignored.urls         : NULL
 $ r.version                : NULL
 $ snapshot.type            : chr "implicit"
 $ use.cache                : logi TRUE
 $ vcs.ignore.cellar        : logi TRUE
 $ vcs.ignore.library       : logi TRUE
 $ vcs.ignore.local         : logi TRUE
 $ vcs.manage.ignores       : logi TRUE

# Options --------------------------------------------------------------------
List of 8
 $ defaultPackages                     : chr [1:6] "datasets" "utils" "grDevices" "graphics" ...
 $ download.file.method                : chr "libcurl"
 $ download.file.extra                 : NULL
 $ install.packages.compile.from.source: chr "interactive"
 $ pkgType                             : chr "both"
 $ repos                               : Named chr "https://packagemanager.posit.co/cran/latest"
  ..- attr(*, "names")= chr "CRAN"
 $ renv.consent                        : logi TRUE
 $ renv.verbose                        : logi TRUE

# Environment Variables ------------------------------------------------------
HOME                        = C:\Users\Lenovo\Documents
LANG                        = <NA>
MAKE                        = <NA>
R_LIBS                      = <NA>
R_LIBS_SITE                 = C:/PROGRA~1/R/R-43~1.1/site-library
R_LIBS_USER                 = C:/Users/Lenovo/Desktop/RProjects/the_app/renv/library/R-4.3/x86_64-w64-mingw32
RENV_DEFAULT_R_ENVIRON      = <NA>
RENV_DEFAULT_R_ENVIRON_USER = <NA>
RENV_DEFAULT_R_LIBS         = <NA>
RENV_DEFAULT_R_LIBS_SITE    = C:/PROGRA~1/R/R-43~1.1/site-library
RENV_DEFAULT_R_LIBS_USER    = C:\Users\Lenovo\AppData\Local/R/win-library/4.3
RENV_DEFAULT_R_PROFILE      = <NA>
RENV_DEFAULT_R_PROFILE_USER = <NA>
RENV_PROJECT                = C:/Users/Lenovo/Desktop/RProjects/the_app

# PATH -----------------------------------------------------------------------
- C:\Users\Lenovo\OriPrograms\Scripts
- C:\Users\Lenovo\OriPrograms
- c:\rtools43\x86_64-w64-mingw32.static.posix\bin
- c:\rtools43\usr\bin
- C:\Program Files\R\R-4.3.1\bin\x64
- C:\Program Files\R\R-4.3.1\bin\x64
- C:\Program Files (x86)\VMware\VMware Player\bin\
- C:\Program Files (x86)\Common Files\Oracle\Java\javapath
- C:\php
- C:\Program Files\MiKTeX 2.9\miktex\bin\x64\
- C:\Program Files\Git\cmd
- C:\Program Files\PostgreSQL\14\bin
- C:\Program Files\PostgreSQL\14\lib
- C:\Program Files\Google\Google Apps Migration\
- C:\Users\Lenovo\anaconda3\Library\bin
- C:\Python36-32
- C:\Python36-32\Lib\site-packages
- C:\Python36-32\Scripts
- C:\Users\Lenovo\OriPrograms\Microsoft VS Code\bin
- C:\Users\Lenovo\anaconda3\Scripts
- C:\Program Files\RStudio\resources\app\bin\quarto\bin
- C:\Program Files\RStudio\resources\app\bin\postback

# Cache ----------------------------------------------------------------------
There are a total of 37 packages installed in the renv cache.
Cache path: "C:/Users/Lenovo/AppData/Local/R/cache/R/renv/cache/v5/R-4.3/x86_64-w64-mingw32"

我的问题是我们如何解决这个问题?非常感谢任何建议。

r collaboration renv r-environment user-environment
1个回答
0
投票

因此,正如评论中所建议的,这个问题是通过首先在项目目录中创建

.Renviron
文件,然后将以下行添加到该文件中来解决的(
.Renviron
):

Sys.setenv(RENV_DOWNLOAD_METHOD = getOption("download.file.method"))

并保存它。

© www.soinside.com 2019 - 2024. All rights reserved.