gpt4 book ai didi

r - 自动安装自制包的依赖库

转载 作者:行者123 更新时间:2023-12-02 04:03:27 24 4
gpt4 key购买 nike

我有一个关于如何在从源安装自制包时自动安装依赖库的问题。

基本上,DESCRIPTION文件看起来像:

Package: mypackage
Type: Package
Title: mypackage_title
Version: 0.1.0
Author: test
Maintainer: test <test @example.com>
Description: More about what it does (maybe more than one line)
Depends:
dplyr,
stringr
License: MIT
LazyData: TRUE
RoxygenNote: 5.0.1

我关注了guide并创建了一个.tar.gz文件。当我分发此软件包时,用户将从源安装。另外,我期望的是,从这个源码安装中,可以得到dplyr这样的依赖库和stringr如果这两个不可用,将自动安装。

我在虚拟机中进行了测试,但遇到了以下错误。那么对于这个问题有什么建议吗?提前致谢!

install.packages("path_to_my_tar.gz", repos=NULL, type="source")
Error: dependencies 'dplyr', 'stringr' are not available for package

更新:我尝试了其他几种方法,但仍然失败......

方法 1

install.packages("path/to/my/package", repos = NULL, type = "source")
ERROR: dependencies 'dplyr', 'stringr' are not available for package

方法2:放入my package , dplyr ,和stringr进入path/to/my/package/folder

install.packages("path/to/my/package", repos =  "path/to/my/package/folder/", type = "source")
Warning in install.packages :
unable to access index for repository path/to/my/package/folder/src/contrib:
scheme not supported in URL 'path/to/my/package/folder/src/contrib/PACKAGES'
Warning in install.packages :
my packageis not available (for R version 3.3.1)

方法3:放入my package , dplyr ,和stringr进入path/to/my/package/folder使用contriburl

install.packages("path/to/my/package", contriburl = "path/to/my/package/folder/", type = "source")
Installing package into my package (as lib?is unspecified)
Warning in install.packages :
unable to access index for repository path/to/my/package/folder/:
scheme not supported in URL 'path/to/my/package/folder/PACKAGES'
Warning in install.packages :
my package is not available (for R version 3.3.1)

方法 4:

install.packages("ProdComp08032016_0.1.2.tar.gz", repos = c("file://C:/Users/TH2/Downloads/", "http://cran.us.r-project.org"), type = "source") Installing package into :/Users/TH2/Documents/R/win-library/3.3?(as ib?is unspecified) Warning in install.packages : cannot open compressed file '//C:/Users/TH2/Downloads/src/contrib/PACKAGES', probable reason 'No such file or directory' Error in install.packages : cannot open the connection

方法 5:

install.packages("ProdComp08032016_0.1.2.tar.gz", repos = c("C:/Users/TH2/Downloads/", "http://cran.us.r-project.org"), type = "source") Installing package into :/Users/TH2/Documents/R/win-library/3.3?(as ib?is unspecified) Warning in install.packages : unable to access index for repository C:/Users/TH2/Downloads/src/contrib: scheme not supported in URL 'C:/Users/TH2/Downloads/src/contrib/PACKAGES' Warning in install.packages : package rodComp08032016_0.1.2.tar.gz?is not available (for R version 3.3.1)

最佳答案

编辑

根据这个重复的问题,Package dependencies when installing from source in R ,命令

install.packages(pkgs = my.package.name, repos = c("file://path/to/my/custom/repo", "http://cran.somepage.org"))

可以使工作,如果你 create a local R repository .

另一个选项是将包制作为 GIT 项目并使用

devtools::install_local("path/to/package.tar.gz")
<小时/>

我没有准备好测试的包,但我的猜测是 repos = NULL 螺丝 install.packages 寻找包的依赖项。

看看 ?install.packages 看起来你运气不好,没有将依赖项也放入本地存储库:

Arguments

pkgs character vector of the names of packages whose current versions should be downloaded from the repositories. If repos = NULL, a character vector of file paths of ‘.zip’ files containing binary builds of packages. (http:// and file:// URLs are also accepted and the files will be downloaded and installed from local copies.) Source directories or file paths or URLs of archives may be specified with type = "source", but some packages need suitable tools installed (see the ‘Details’ section). If this is missing or a zero-length character vector, a listbox of available packages is presented where possible in an interactive R session.
lib character vector giving the library directories where to install the packages. Recycled as needed. If missing, defaults to the first element of .libPaths().
repos character vector, the base URL(s) of the repositories to use, e.g., the URL of a CRAN mirror such as "http://cran.us.r-project.org". For more details on supported URL schemes see url. Can be NULL to install from local files, directories or URLs: this will be inferred by extension from pkgs if of length one.

这是我的两个猜测:

install.packages(pkgs = "package", ..., repos = c("file://path.to.tar.gz", "http://path.to.cran.mirror")) # Try to specify the path to your package as another repo
install.packages(pkgs = "file://path.to.tar.gz.file") # Leave repos alone and hope the file:// suffices

请告诉我它们是否有效:)

关于r - 自动安装自制包的依赖库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38732493/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com