Automatically install dependent libraries for a self-made package

流过昼夜 提交于 2019-12-23 20:04:10

问题


I have a question regarding on how to automatically install dependent libraries while installing a self-made package from source.

Basically, the DESCRIPTION file looks like:

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

I followed the guide and created a .tar.gz file. When I distribute this package, a user will install from the source. In addition, what I expect is that from this source installation, dependent libraries such as dplyr and stringr will be installed automatically if those two are not available.

I tested in a virtual machine but ran into the following errors. So any suggestions on this issue? Thanks in advance!

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

Update: I tried a couple of other approaches but still failed...

Approach 1

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

Approach 2: putting my package, dplyr, and stringr into 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)

Approach 3: putting my package, dplyr, and stringr into path/to/my/package/folder using 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)

Approach 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

Approach 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)


回答1:


EDIT

As per this duplicate question, Package dependencies when installing from source in R, the command

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

can be made to work, if you create a local R repository.

The other option is to make the package a GIT project and use

devtools::install_local("path/to/package.tar.gz")

I don't have a package ready for testing, but my guess is repos = NULL screws install.packages looking for dependencies of your package.

Looking at ?install.packages looks like you have bad luck without putting your dependencies in the local repository as well:

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.

Here are my two guesses:

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

Please let me know whether they work or not :)




回答2:


No guarantees, but perhaps

devtools::install_local("path_to_my_tar.gz")

and if that doesn't quite work, try with dependencies=TRUE?



来源:https://stackoverflow.com/questions/38732493/automatically-install-dependent-libraries-for-a-self-made-package

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!