pacman icon indicating copy to clipboard operation
pacman copied to clipboard

Installing from GitHub and specifying "type"

Open alapo opened this issue 6 years ago • 3 comments

Big fan of the package. I was curious if anyone knew how I should install the following package using pacman. The devtools syntax would be:

devtools::install_github("benmarwick/wordcountaddin", type = "source", dependencies = TRUE)

I read through the documentation but was unable to find a way to specify the type when using p_install_gh

alapo avatar Apr 18 '19 14:04 alapo

Hi @alapo

The argument section of the help page (?p_install_gh) mentions:

...       Additional parameters to pass to install_github.

You can pass on the type = "source" parameter from pacman::p_install_gh() to remotes::install_github().

Therefore, your function call is possible with p_install_gh as well:

pacman::p_install_gh("benmarwick/wordcountaddin", type = "source", dependencies = TRUE)

LoHertel avatar May 05 '19 08:05 LoHertel

Thank you for your response @LoHertel I am attempting to make a reproducible document for other members of my lab.

The issue is that one package (wordcountaddin) relies on source where the second (apastats) relies on a subdirectory such that if I was to write each line individually it would be

pacman::p_install_gh("benmarwick/wordcountaddin", type = "source", dependencies = TRUE)

Curiously this following line using pacman doesnt work due to "incorrect capitalization specification"

pacman::p_install_gh( "achetverikov/apastats", subdir="apastats" )

But using devtools it does work using the same syntax

devtools::install_github('achetverikov/apastats',subdir='apastats')

I originally had all the GitHub packages set up as follows (which works until this example)

pacman::p_install_gh( c("benmarwick/wordcountaddin", "achetverikov/apastats") )

Do you have any recommendation on how you would pass this in one line?

Perhaps this is redundant but I've found this package to be particularly great for beginners to the RMarkdown environment who might be averse to calling install.packages("PackageName") and library(PackageName)

Sorry for the extended question but I (and my lab mates) appreciate your input

alapo avatar May 13 '19 20:05 alapo

Please use p_load_gh() instead

You wrote that you want to circumvent calling install.packages("PackageName") and library(PackageName) by using pacman. In that case, please use pacman::p_load_gh() instead. Because pacman::p_install_gh() just installs packages and is not loading them.

pacman::p_load_gh('benmarwick/wordcountaddin', 'achetverikov/apastats/apastats', type = 'source', dependencies = NA)

The difference between devtools::install_github(), pacman::p_install_gh(), and pacman::p_load_gh() is:

  • devtools::install_github()

    • Installs packages only.
    • Installs only necessary dependencies of packages by default (dependencies = NA). This means dependencies of three categories ("Depends", "Imports" and "LinkingTo").
  • pacman::p_install_gh()

    • Installs packages only.
    • Installs all dependencies of packages by default (dependencies = TRUE). This means dependencies of all four categories ( "Depends", "Imports", "LinkingTo" and "Suggests").
    • If multiple packages should be installed, create a vector with all names c(..., ...) and pass it to the function.
  • pacman::p_load_gh()

    • Installs and loads packages. If they are installed already, the function just loads them.
    • Installs all dependencies of packages by default (dependencies = TRUE). This means dependencies of all four categories ( "Depends", "Imports", "LinkingTo" and "Suggests").
    • If multiple packages should be loaded, give the names as separate arguments to the function.

Call all in one statement without subdir

suppressWarnings(pacman::p_install_gh(c('benmarwick/wordcountaddin', 'achetverikov/apastats/apastats'), type = 'source', dependencies = NA))

If you want to install multiple packages at the same time, you can not combine it with the subdir argument. Instead, you could add the subdirectory name after the repository name.

At the moment, p_install_gh() throws a warning when multiple packages are installed at the same time. Therefore, you could wrap it with suppressWarnings(). When using p_load_gh(), the warning does not show up.

LoHertel avatar May 20 '19 22:05 LoHertel