Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erroneous use of getNamespaceVersion() in a comparison #607

Closed
TimTaylor opened this issue Oct 17, 2024 · 2 comments · Fixed by #609
Closed

Erroneous use of getNamespaceVersion() in a comparison #607

TimTaylor opened this issue Oct 17, 2024 · 2 comments · Fixed by #609

Comments

@TimTaylor
Copy link

TimTaylor commented Oct 17, 2024

As pointed out in this thread on R-devel, the following line could break at a future (sufficiently high) release of reticulate:

if(getNamespaceVersion("reticulate") >= "1.36.0") "r-keras"

getNamespaceVersion("reticulate")
#>  version 
#> "1.39.0"
getNamespaceVersion("reticulate") >= "1.99.0"
#> version 
#>   FALSE
getNamespaceVersion("reticulate") >= "1.100.0"
#> version 
#>    TRUE

This can be solved with either the suggested compareVersion() or via wrapping with as.package_version():

compareVersion(getNamespaceVersion("reticulate"), "1.38.0") >= 0
#> [1] TRUE
compareVersion(getNamespaceVersion("reticulate"), "1.100.0") >= 0
#> [1] FALSE

as.package_version(getNamespaceVersion("reticulate")) >= "1.38.0"
#> [1] TRUE
as.package_version(getNamespaceVersion("reticulate")) >= "1.100.0"
#> [1] FALSE
@eddelbuettel
Copy link
Collaborator

eddelbuettel commented Oct 17, 2024

FWIW that is due to a recent-ish change in R itself. The change, IIRC, occurred on the 'other side' i.e. we now need to promote the comparison string:

edd@rob:~$ docker run --rm -ti r-base:4.3.3 Rscript -e 'getNamespaceVersion("base") > as.package_version("4.3.0")'
[1] TRUE
edd@rob:~$ docker run --rm -ti r-base:4.3.3 Rscript -e 'getNamespaceVersion("base") > as.package_version("4.4.0")'
[1] FALSE
edd@rob:~$ 

Ditto for 4.4.1 directly:

edd@rob:~$ Rscript -e 'getNamespaceVersion("base") > as.package_version("4.3.0")'
[1] TRUE
edd@rob:~$ Rscript -e 'getNamespaceVersion("base") < as.package_version("4.5.0")'
[1] TRUE
edd@rob:~$ 

But your overall point stands: reticulate needs such a cast either on the left or right to have the comparison work correctly.

@t-kalinowski
Copy link
Member

Thank you both! This is very helpful and much appreciated. The fix will be on main shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants