Hi all, I was trying to download the source code of a package using the versioned urls (https://CRAN.R-project.org/package=%s&version=%s). I used packageVersion to get the version number but it failed because it uses the function pacakge_version that replaces the "-" the version number had. Indeed, the examples show that package_version("1.2-4") represents it as "1.2.4". However, when converted back to characters (via as.character or similar approaches) it keeps the "." instead of reverting back to "-". The work around is essay enough: packageVersion(pkg, field = "Version") so my code is fixed but it might not be obvious in other cases. Could the round trip revert to the original package version provided by the maintainer ( so that identical(as.character(package_version("1.2-4")), "1.2-4") is TRUE) ? This would simplify manipulations of package versions (currently ~2000 packages on CRAN use "-" on their version). Cheers, Llu?s Revilla PS: The description at the top of the help page ?download.packages doesn't fully match the content. I think it refers to the functions documented on ?update.packages. Perhaps something from the first paragraph on details can be moved to the description
Round trip between package_version and character
5 messages · Lluís Revilla, Henrik Bengtsson, Josiah Parry +1 more
A possible solution could be to preserve the original version string as an attribute, which then as.character() could use, e.g.
str(v)
List of 1 $ :Classes 'package_version', 'numeric_version' hidden list of 1 ..$ : int [1:3] 1 2 4 - attr(*, "class")= chr [1:2] "package_version" "numeric_version" - attr(*, "source")= chr "1.2-4" I don't want to divert this "feature request", but a related discussion is whether we really need to support anything but x.y.z? Would it make sense to deprecate support for hyphenated version components? The one argument I recall for supporting hyphens was for "date" versions, e.g. YYYY-MM-DD, but R has dropped leading zeros for a while now;
package_version("2026-01-17")
[1] '2026.1.17' and CRAN doesn't accept them; * checking CRAN incoming feasibility (4.1s) ... Version contains leading zeroes (2026-01-17) /Henrik PS.I didn't know that <https://CRAN.R-project.org/package=%s&version=%s> works -it downloads <package>_<version>.tar.gz. Thanks.
On Sat, Jan 17, 2026 at 4:10?AM Llu?s Revilla <lluis.revilla at gmail.com> wrote:
Hi all, I was trying to download the source code of a package using the versioned urls (https://CRAN.R-project.org/package=%s&version=%s). I used packageVersion to get the version number but it failed because it uses the function pacakge_version that replaces the "-" the version number had. Indeed, the examples show that package_version("1.2-4") represents it as "1.2.4". However, when converted back to characters (via as.character or similar approaches) it keeps the "." instead of reverting back to "-". The work around is essay enough: packageVersion(pkg, field = "Version") so my code is fixed but it might not be obvious in other cases. Could the round trip revert to the original package version provided by the maintainer ( so that identical(as.character(package_version("1.2-4")), "1.2-4") is TRUE) ? This would simplify manipulations of package versions (currently ~2000 packages on CRAN use "-" on their version). Cheers, Llu?s Revilla PS: The description at the top of the help page ?download.packages doesn't fully match the content. I think it refers to the functions documented on ?update.packages. Perhaps something from the first paragraph on details can be moved to the description [[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
It would be really nice if the full semantic versioning spec was supported in R. I can understand why only major.minor.patch would be supported for CRAN. But for an R package in a development stage, it would be wonderful to support pre-release and build metadata. Use of `-` in semver to determine pre-release: https://semver.org/#spec-item-9 The semver package does a pretty decent job of handling the semver spec: ver_str <- "1.0.0-alpha+commit-hash" package_version(ver_str) #> Error: invalid version specification '1.0.0-alpha+commit-hash' (sv <- semver::parse_version(ver_str)) #> [1] Maj: 1 Min: 0 Pat: 0 Pre: alpha Bld: commit-hash as.character(sv) #> [1] "1.0.0-alpha+commit-hash" On Sat, Jan 17, 2026 at 10:29?AM Henrik Bengtsson <
henrik.bengtsson at gmail.com> wrote:
A possible solution could be to preserve the original version string as an attribute, which then as.character() could use, e.g.
str(v)
List of 1 $ :Classes 'package_version', 'numeric_version' hidden list of 1 ..$ : int [1:3] 1 2 4 - attr(*, "class")= chr [1:2] "package_version" "numeric_version" - attr(*, "source")= chr "1.2-4" I don't want to divert this "feature request", but a related discussion is whether we really need to support anything but x.y.z? Would it make sense to deprecate support for hyphenated version components? The one argument I recall for supporting hyphens was for "date" versions, e.g. YYYY-MM-DD, but R has dropped leading zeros for a while now;
package_version("2026-01-17")
[1] '2026.1.17' and CRAN doesn't accept them; * checking CRAN incoming feasibility (4.1s) ... Version contains leading zeroes (2026-01-17) /Henrik PS.I didn't know that <https://CRAN.R-project.org/package=%s&version=%s> works -it downloads <package>_<version>.tar.gz. Thanks. On Sat, Jan 17, 2026 at 4:10?AM Llu?s Revilla <lluis.revilla at gmail.com> wrote:
Hi all, I was trying to download the source code of a package using the versioned urls (https://CRAN.R-project.org/package=%s&version=%s). I used packageVersion to get the version number but it failed because it uses
the
function pacakge_version that replaces the "-" the version number had.
Indeed, the examples show that package_version("1.2-4") represents it as
"1.2.4". However, when converted back to characters (via as.character or
similar approaches) it keeps the "." instead of reverting back to "-".
The
work around is essay enough: packageVersion(pkg, field = "Version") so my code is fixed but it might not be obvious in other cases. Could the round trip revert to the original package version provided by
the
maintainer ( so that identical(as.character(package_version("1.2-4")),
"1.2-4") is TRUE) ?
This would simplify manipulations of package versions (currently ~2000
packages on CRAN use "-" on their version).
Cheers,
Llu?s Revilla
PS: The description at the top of the help page ?download.packages
doesn't
fully match the content. I think it refers to the functions documented on ?update.packages. Perhaps something from the first paragraph on details
can
be moved to the description
[[alternative HTML version deleted]]
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Le Sat, Jan 17, 2026 at 11:02:12AM -0800, Josiah Parry a ?crit :
It would be really nice if the full semantic versioning spec was supported in R. I can understand why only major.minor.patch would be supported for CRAN. But for an R package in a development stage, it would be wonderful to support pre-release and build metadata. Use of `-` in semver to determine pre-release: https://semver.org/#spec-item-9
In Debian we have long handled this use?case by using a tilde (~) in version strings?well before semver was formalized. If you like the semantics of pre?release identifiers but want to avoid changing the meaning of - in existing R versioning, adopting ~ might be a practical alternative. Relevant documentation: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version Have a nice week-end, Charles Plessy
It is good to see so much interest in version numbers! R doesn't require Calendar versioning (https://calver.org/), Semantic Versioning or Debian versions. The package_version describe the version numbers as:
Numeric versions are sequences of one or more non-negative integers, usually (e.g., in package ?DESCRIPTION? files) represented as character strings with the elements of the sequence concatenated and separated by single ??.?? or ??-?? characters. R package versions consist of at least two such integers
The R-extension manual describes them in the section "The DESCRIPTION file":
This is a sequence of at least two (and usually three) non-negative integers separated by single ?.? or ?-? characters. The canonical form is as shown in the example, and a version such as ?0.01? or ?0.01.0? will be handled as if it were ?0.1-0?.
Note that here there are some versions with a leading 0 (which package_version accepts!). I think fully supporting any of these versions schemes would involve changing how R itself resolves dependencies for packages (mainly to cover the [:alpha:] characters). This is a much larger patch/project than what I asked for and in any way R still would need to manipulate (and compre) them easily. In terms of implementation if the attribute approach is added it could be used by format.numeric_version. But I'm not sure if any package relies on this to remove any "-" and leading 0 present...
From a quick check on the first 40 packages from 100 that use the
function none would be impacted as it is primarily used to enable or disable features according to the versions of dependencies installed. Missatge de Charles Plessy <charles-listes+rd at plessy.org> del dia dg., 18 de gen. 2026 a les 2:40:
Le Sat, Jan 17, 2026 at 11:02:12AM -0800, Josiah Parry a ?crit :
It would be really nice if the full semantic versioning spec was supported in R. I can understand why only major.minor.patch would be supported for CRAN. But for an R package in a development stage, it would be wonderful to support pre-release and build metadata. Use of `-` in semver to determine pre-release: https://semver.org/#spec-item-9
In Debian we have long handled this use?case by using a tilde (~) in version strings?well before semver was formalized. If you like the semantics of pre?release identifiers but want to avoid changing the meaning of - in existing R versioning, adopting ~ might be a practical alternative. Relevant documentation: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version Have a nice week-end, Charles Plessy
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel