remotes icon indicating copy to clipboard operation
remotes copied to clipboard

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

Open marqisoft opened this issue 2 years ago • 2 comments
trafficstars

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 list of links in the online catalog of archives seems to be sorted alphabetically,
  • the comparison done inside the install_version() function does not deal with version info as numeric but as text.

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

marqisoft avatar Mar 28 '23 14:03 marqisoft

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.

gaborcsardi avatar Mar 28 '23 16:03 gaborcsardi

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 ...

davidkim83 avatar May 22 '23 03:05 davidkim83