r-lib / remotes

Install R packages from GitHub, GitLab, Bitbucket, git, svn repositories, URLs
https://remotes.r-lib.org/
Other
332 stars 152 forks source link

Incorrect version being installed by function install_version("zoo", "< 1.8.11") #753

Open marqisoft opened 1 year ago

marqisoft commented 1 year ago

When using the install_version() function with a version argument including comparison operator(s) the behavior is not always correct. Here is an example when installing different versions of the zoo package:

# Last version: currently it is 1.8.11
install.packages("zoo")

# This wrongly installs 1.8.9 rather than 1.8.10; why so?
install_version("zoo", "< 1.8.11")

# To confirm that other version exists:
install_version("zoo", "1.8.10")

# And we can also see it online here: https://cloud.r-project.org/src/contrib/Archive/zoo/

The possible causes of this issue I think are likely that... considering the Catalog (here of package zoo) online: https://cloud.r-project.org/src/contrib/Archive/zoo/

The solution I think, would be to transform the version numbers in a 1+3 column data frame, by splitting the version info into parts: MAJOR . MINOR . PATCH ... and try to convert them to numeric. If the last column does not want to be converted to numeric, keep it as character. The dataframe listing the available versions would thus have 4 columns: 1) character string of the version; 2) Major; 3) Minor; 4) Patch. Then, the dataframe can be sorted numerically. This way, a patch 10 will always be positioned just before 11, even if it was not the case in the web page of the Catalog (link above).

This is just a partial solution, suggestion, to solve this issue. And I might be going in a wrong direction... The cause of this issue might be something else!

In short, I found it strange that install_version("zoo", "< 1.8.11") did install package zoo version 1.8.9 rather than 1.8.10 in my R.

If you can test it and maybe find a solution?

Thanks

gaborcsardi commented 1 year ago

Thanks for the report! CRAN used to have the files in the right order, but not any more. It is not a high priority for us to fix this, but a PR is welcome.

davidkim83 commented 1 year ago

If sorting is the problem, perhaps this would help? At least it would allow users to install the latest version if there is no version string given.

info <- info[order(info$mtime),] in package_find_archives of R/install-version.R, just before returning the info. https://github.com/r-lib/remotes/blob/main/R/install-version.R#L161

image

If the result is not null, then the archive.rds should have a modified time. Unlike ctime and atime, which look like processed dates by CRAN, the mtime seem to be the last modified date of the package file itself.

image

It would be better than nothing I suppose. I'd submit a PR myself, but unfortunately I've never developed R packages ...