Skip to content

lockfile_install() reinstalls source packages every time when CRAN is cran.r-universe.dev #486

Open

Description

@jgabry

I noticed this on cmdstanr's windows-11-arm GitHub Actions job, where setup-r-dependencies restores a 93 MB library from the cache and then pak::lockfile_install() rebuilds the whole thing from source anyway ("Will install 91 packages", "added 90, dld 90", about 26 minutes). The same workflow on windows-latest says "kept 86, added 3" and is done in 20 seconds. See https://github.com/stan-dev/cmdstanr/actions/runs/37052454400/job/110988918897 setup-r-dependencies step.

I did some digging (Claude assisted) and I think this is because the R build that setup-r installs on Windows ARM sets CRAN to https://cran.r-universe.dev. With pak 0.11.1 every entry in our lockfile is "platform": "source", "repotype": "cran", and installedok_remote_cran() requires

    identical(installed[["repository"]], "CRAN")

But source tarballs from r-universe use Repository: https://cran.r-universe.dev in DESCRIPTION, and add_metadata() writes the Remote* fields but doesn't touch Repository, so nothing pak installed from r-universe can pass the check and pkgplan_update() just reinstalls everything on every run.

I asked Claude to come up with this minimal reproducible example (I see the same thing with pak 0.9.2 and 0.11.1.9000):

    Sys.setenv(PKG_PLATFORMS = "source")
    options(repos = c(CRAN = "https://cran.r-universe.dev"))
    lib <- tempfile(); dir.create(lib)
    pak::lockfile_create("abind", lockfile = "pkg.lock", lib = NULL)
    pak::lockfile_install("pkg.lock", lib = lib)  # added 1
    pak::lockfile_install("pkg.lock", lib = lib)  # added 1 again
    packageDescription("abind", lib.loc = lib)$Repository
    #> "https://cran.r-universe.dev"

If repos is set to c(CRAN = "https://cloud.r-project.org") the second call says "kept 1" and Repository is "CRAN".

Would a solution be for the source branch to also accept a package whose RemoteRepos matches the lockfile entry, the way installedok_remote_standard() does for source packages from other repos? pak writes RemoteRepos at install time, so anything pak installed would pass.

Activity

  1. jgabry commented on Oct 4, 2026

    @jgabry
    Author

    I should have mentioned that for our case, it seems like switching that job to pak-version: devel works around the problem because the devel pak gets r-universe's Windows ARM64 binaries (r-lib/pkgcache#142) and binary entries are checked on Built instead of Repository. The dependency step went from 26 minutes to 2 minutes (stan-dev/cmdstanr#1304). Having said that, this still matters for anyone installing source packages from an r-universe mirror.

  2. gaborcsardi commented on Oct 4, 2026

    @gaborcsardi
    Member

    Can you show the code what you run, e.g. how do you set options(repos)?

    Having said that, this still matters for anyone installing source packages from an r-universe mirror.

    I am not sure if that's a problem in practice. I believe that most people are using r-universe mirrors exactly for the binary packages.

  3. gaborcsardi commented on Oct 4, 2026

    @gaborcsardi
    Member

    Here is the code that decides whether such a package should be updated:

    identical(installed[["repository"]], "CRAN")

  4. jgabry commented on Oct 5, 2026

    @jgabry
    Author

    Thanks for the quick response.

    I am not sure if that's a problem in practice. I believe that most people are using r-universe mirrors exactly for the binary packages.

    Yeah, I agree. I guess it could still affect a package that has no binary on r-universe and so falls back to source, in which case it would be rebuilt on every lockfile_install(). But maybe that's not worth a change and this can be closed.

    To answer your other question, we're not setting options(repos) ourselves, we just use standard r-lib/actions steps on a windows-11-arm runner:

        - uses: r-lib/actions/setup-r@v2
          with:
            r-version: 'release'
        - uses: r-lib/actions/setup-r-dependencies@v2
          with:
            cache: "always"
            extra-packages: any::rcmdcheck, local::.
    

    The R that gets installed there is the community Windows ARM64 build from github.com/r-devel/windows-arm64 (R 4.6.1 in our case, CRAN has no Windows ARM64 installer). That sets CRAN = https://cran.r-universe.dev (explained in the README there). setup-r normally points CRAN at cran.rstudio.com (or I think P3M on x86), but if the R installer already set a mirror, setup-r keeps it unless you also pass the cran input and so on this runner CRAN stays as r-universe. The "Repo status" that setup-r-dependencies prints with pak 0.11.1 is

        name                                 url                           type platform path
        CRAN                                 https://cran.r-universe.dev   cran source   src/contrib
        BIOC                                 https://bioc-release.r-universe.dev cranlike source src/contrib
    

    and every lockfile entry is "platform": "source", "repotype": "cran".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions