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

building a miniCRAN 3.4 using R 3.6 #129

Closed
Courvoisier13 opened this issue Oct 28, 2019 · 8 comments
Closed

building a miniCRAN 3.4 using R 3.6 #129

Courvoisier13 opened this issue Oct 28, 2019 · 8 comments
Assignees
Milestone

Comments

@Courvoisier13
Copy link

Courvoisier13 commented Oct 28, 2019

I am using 3.6.1 and building a miniCRAN for R 3.4.4.

The new packages get added correctly and build a miniCRAN for R 3.4.4 correctly. However, when trying to install packages from the miniCRAN using the R 3.4.4 I get the error

   Warning in install.packages :
    unable to access index for repository https://cran.rstudio.com/src/contrib:
    cannot open URL 'https://cran.rstudio.com/src/contrib/PACKAGES'

  Installing packages into ‘D:/libraries/R/libraries’ (as ‘lib’ is unspecified)
  Error in install.packages : cannot read workspace version 3 written by R 3.6.1; need R 3.5.0 or newer

I found the issue and it was the index stored as RDS version 3

  > readRDS("path/miniCRAN3.4/bin/windows/contrib/3.4/PACKAGES.rds")
  Error in readRDS("path/miniCRAN3.4/bin/windows/contrib/3.4/PACKAGES.rds") : 
    cannot read workspace version 3 written by R 3.6.1; need R 3.5.0 or newer

So I read the file in R 3.6, and overwrote it with writeRDS(, version = 2) and that solved the issue and I was able to install the packages in R 3.4.

So miniCRAN puts the right version of the libraries in the folder, but the index is an .rds and that is no longer compatible by default across R=<3.5 to R>=3.6

@achubaty
Copy link
Collaborator

we are using write_packages as a wrapper for tools::write_PACKAGES to create the PACKAGES files. To work around this (within write_packages) using the approach suggested above, we would need to add an argument to pass in the Rversion.

@Courvoisier13
Copy link
Author

Hi, I actually solved the issue by setting env variable R_DEFAULT_SAVE_VERSION = 2 and R_DEFAULT_SERIALIZE_VERSION = 2. This way the .rds gets saved as version 2 (pre R 3.5). It's not ideal but it works while the team makes the switch.

@achubaty
Copy link
Collaborator

@andrie we should add this to an example/vignette. I'll add it to my to do list, but I don't know when I'll get to it.

@andrie andrie self-assigned this Jul 12, 2020
@andrie andrie added this to the v0.2.13 milestone Jul 12, 2020
@andrie
Copy link
Owner

andrie commented Jul 12, 2020

I'm adding an r_version argument to write_packages. (Now in the process of fixing the errors this introduces!)

@lucazav
Copy link

lucazav commented Nov 20, 2022

I've just created a miniCRAN repository for an offline installation of R 3.4.4 using R 4.2.2. I installed the dev version of miniCRAN to be sure that the upon mentioned commit was included (its version is 0.2.16.9000). Here the code to create the repository using R 4.2.2:

library("miniCRAN")

# Reference the CRAN 0-Clud mirror
CRAN_mirror <- c(CRAN = "https://cloud.r-project.org")

# Declare the packages' destination folder in your local machine
# and create it
local_repo <- "C:/miniCRAN_R344"
dir.create(local_repo)

# Declare the packages you want to install (they can be more than one)
pkgs_needed <- c("ggplot2")

# Reference the package dependencies and add them to the packages declaration
pkgs_with_dependencies <- pkgDep(pkgs_needed, repos = CRAN_mirror)

# Download all packages with version compatible with the engine R 3.4.4 
makeRepo(pkgs_with_dependencies, path = local_repo,
         repos = CRAN_mirror,
         type = "win.binary",
         Rversion = "3.4.4")

When trying to install packages in R 3.4.4, I'm getting the following error:

Error in readRDS(dest) :
cannot read workspace version 3 written by R 4.2.2; need R 3.5.0 or newer

Does the above commit still need to be committed?

@andrie
Copy link
Owner

andrie commented Nov 20, 2022

That commit was merged a long time ago, but it's clear that it didn't solve the root cause.

As a workaround I suggest you either use R-3.5 or earlier to create the miniCRAN, or use the advice earlier in this thread (#129 (comment))

@andrie
Copy link
Owner

andrie commented Nov 24, 2022

The earlier supposed "fix" that I wrote didn't work at all. I also couldn't get the proposed workaround to work as expected.

After some experimentation, I realised it's quite trivial to use tools::write_PACKAGES() to write the .rds file, then read it into memory and write it out again, but this time using version = 2.

I have this working in my local main branch and will commit this soon.

@andrie
Copy link
Owner

andrie commented Mar 24, 2024

Can we close this now?

@andrie andrie modified the milestones: v0.2.13, v0.2.17 Mar 27, 2024
@andrie andrie closed this as completed Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants