Skip to content
Back to formatted view

Raw Message

Message-ID: <CAN+W6_vnr9hw-br6YraEqBk3rrdzQY17GCoUkpK5bDNpySppdQ@mail.gmail.com>
Date: 2026-01-17T12:10:15Z
From: LluĂ­s Revilla
Subject: Round trip between package_version and character

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