b-rodrigues / rix

Reproducible development environments for R with Nix
https://b-rodrigues.github.io/rix/
GNU General Public License v3.0
102 stars 11 forks source link

`rix()` fails for CRAN packages if latest version is specified. #210

Open eliocamp opened 5 days ago

eliocamp commented 5 days ago

I get an error if I try to use the latest version of a CRAN package:

library(rix)
rix(r_ver = "latest",
    r_pkgs = "Formula@1.2-5",    # Current version
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)
#> Error: Request `curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://cran.r-project.org/src/contrib/Archive/Formula/Formula_1.2-5.tar.gz&branchName=&commit=')` failed:
#>  The requested URL returned error: 500
#> If it's a Github repo, check the url, branch name and commit.
#> Are these correct? If it's an archived CRAN package, check the name
#> of the package and the version number.
rix(r_ver = "latest",
    r_pkgs = "Formula@1.2-4",    # Old version works
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)

rix(r_ver = "latest",
    r_pkgs = "ggplot2@3.5.1",    # Happens with other packages
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)
#> Error: Request `curl::curl_fetch_memory(url = 'http://git2nixsha.dev:1506/hash?repo_url=https://cran.r-project.org/src/contrib/Archive/ggplot2/ggplot2_3.5.1.tar.gz&branchName=&commit=')` failed:
#>  The requested URL returned error: 500
#> If it's a Github repo, check the url, branch name and commit.
#> Are these correct? If it's an archived CRAN package, check the name
#> of the package and the version number.

My intuition is that rix() must be looking into CRAN archives. But those only host old versions so it falls back to treating it like a git repo instead.

b-rodrigues commented 5 days ago

yes indeed, you are correct. We would like people to use the actual packages from nixpkgs, and only provide specifying old versions as a convenience. If you absolutely need bleeding edge packages, you can use r_ver = "frozen_edge". See https://b-rodrigues.github.io/rix/articles/z-bleeding_edge.html for more details

eliocamp commented 5 days ago

So is it impossible to specify an old R version and the current version of an R package? (say I want to use R 4.3.1 with Formula 1.2-5, which is the current version but also the one available at the time of 4.3.1)

b-rodrigues commented 5 days ago

Due to how packages are updated in nixpkgs, there's no "easy" way of doing it. You can install it from Github though, or you could override the package definition, but we didn't document how to do it as this requires familiarity with Nix. We are thinking about providing a way to do this in the future though

eliocamp commented 5 days ago

Are

rix(r_ver = "4.4.1",
    r_pkgs = "Formula@1.2-5",  
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)

and

rix(r_ver = "4.4.1",
    r_pkgs = "Formula",
    ide = "rstudio",
    project_path = ".",
    overwrite = TRUE,
    print = FALSE)

equivalent configs? If so, wouldn't it make sense for rix to accept both and create the correct nix config?

b-rodrigues commented 1 day ago

No, because in the first case, Formula will be pulled from CRAN directly, and in the second case, Formula will be pulled from its definition on nixpkgs.

If we want Nix to handle the dependency resolution for us, we need to use the Nix definitions from Nixpkgs. This is why it can be tricky to "mix-and-match" different versions of R and packages with Nix, but also, this should usually not be much of an issue as running one particular (in general older) version of one package with a newer version of R is rarely needed. For example renv wouldn’t allow it, as initializing a project using renv would only download the most up-to-date packages to initialize the project-specific library.

eliocamp commented 1 day ago

But if the installed version is the same, wouldn't it make sense for rix to interpret "pkg@vesion" as "pkg" and pull the package from nix anyway.

b-rodrigues commented 1 day ago

I’ll have to think about this one, but I think it wouldn’t be that easy to implement. Also, I don’t think I want to encourage people to think about individual package versions too much: the idea is to define an environment at a given "snapshot revision" and then just use it. To have something that works like renv, and also ultimately have an renv2nix, we would need to rethink how rix works quite a bit. It’s on the roadmap, but it’ll require more work that we would like leave for a second or third major CRAN release 😄