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 <[email protected]> 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]]
>
> ______________________________________________
> [email protected] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel