trinker / pacman

A package management tools for R
312 stars 37 forks source link

Add a combined form for p_install_version? #74

Open shabbychef opened 8 years ago

shabbychef commented 8 years ago

The interface for p_install_version does, in my mind, scale to a large number of packages. While this looks fine:

p_install_version(
    c("pacman", "testthat"),
    c("0.2.0", "0.9.1")
)

Things get funny for a large number of packages as the two input can get out of sync and hard to maintain:

# I lost count of my input. sad.
p_install_version(c('foo','bar','baz','foofoo','foobar','foobaz'),
  c('0.2.0','0.1.0','1.1.1',????))

Maybe better would be the somewhat 'standard' form of including the version dependency in the string:

p_install_version_new(c('foo>=0.2.0','bar>=0.1.0','baz'))

Without a >= (or >?), it would be understood that the requirement is simply >=0.0.0.

(I have a quick and dirty implementation based on grepl and gsub and p_install_version, but the form of the input has to be nailed down first.)

trinker commented 8 years ago

Sounds reasonable. This is one approach that sounds promising. Passing a named list may also be appealing or a list of paired vectors (though this is a lot of typing).

Can you share your dirty version?

Dasonk commented 8 years ago

I like the suggestion. The main point of pacman is to make things easier for the user and if it gets a little difficult to manage when scaling that doesn't help anybody. A named list or list of pairs would be easy to implement but might make it more tedious for the user. I like the suggestion for the form. I'm not sure the best way to handle something like foo>=0.2.0 if versions 0.2.0 and 0.3.0 and 1.0.0 exist in the world and say 1.0.0 isn't backwards compatible. Might just be easiest to allow specifying the version in the string but requiring exact versions be specified and if nothing is specified then grab the newest version?

shabbychef commented 8 years ago

Not my best work, but here's the hack:

# packages is a char array of the form
# c('package','package >= version')
p_i_v_new <- function(packages) {
    require(pacman)
    pnames <- gsub('\\s*>.+$','',packages)
    hasvers <- grepl('>',packages)
    vernums <- rep('0.0.0',length(packages))
    if (any(hasvers)) {
        vernums[hasvers] <- gsub('^.+>=?\\s*','',packages[hasvers])
    }
    p_install_version(pnames,vernums)
}
# test it:
p_i_v_new(c('dplyr>=0.5','drat>=0.2.0','xts','zoo','fortunes>=1.5'))