3
votes

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)

2
Just to clarify; your virtual machine has a configured internet connection with which it could install said dependencies? What happens if you try to install it from the .tar.gz on your build machine?Jonathan Carroll
@JonathanCarroll, correct. The virtual machine has internet connection. The same installation approach works on my build machine, which had dplyr and stringr installed before.TTT
A basic solution: run install.packages(c("dplyr", "stringr")) before the install.packages("path_to_my_tar.gz", repos=NULL, type="source"). You'll need to update the install.packages() call when you add new dependencies to your package, but that should be fine.Paul Rougieux

2 Answers

3
votes

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

1
votes

No guarantees, but perhaps

devtools::install_local("path_to_my_tar.gz")

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