Get package name when installing from source

I know that you can install .tar.gz or .zip from the source using the following.

install.packages(SOURCE_FILE, repos = NULL, type="source")

I want to be able to determine the name of the package to be installed. So, for example, we could download this amazing package: https://github.com/Dasonk/findPackage/tarball/master?download .

This will give us .tar.gz called Dasonk-findPackage-61907b1.tar.gz. We could rename it to beep.tar.gzand still set as:

 install.packages("beep.tar.gz", repos=NULL, type="source")

How to get the actual name of the package that was installed. I thought I could use it capture.output, but that doesn't work either. Therefore, after use, install.packagesI would like to know what has "findPackage"just been installed.

+4
source share
2 answers

I hate this, but all I could think of:

package_name <- function(package) {
    temp <- tempdir()
    untar(package, exdir = temp)
    out <- c(read.dcf(list.files(temp, pattern="DESCRIPTION", 
        recursive=TRUE, full.names=TRUE), "Package"))
    unlink(temp, recursive = TRUE, force = FALSE)
    out
}

package_name("beep.tar.gz")
+1
source

If you want to install a package, I think the easiest way is to simply get a list of installed packages before and after:

# Grab previously installed packages
start.packages <- installed.packages()[,1]

# Install your new package
install.packages("beep.tar.gz", repos=NULL, type="source")

# Find all new packages
setdiff(installed.packages()[,1], start.packages)

The obvious drawbacks are that you need to install a new package and you will also get all the newly installed dependencies.

0
source

Source: https://habr.com/ru/post/1525956/


All Articles