cannot read workspace version 3 written by R 3.6.0; need R 3.5.0 or newer

I'm running into this error when I build a company internal package on my laptop, move it to SQL Server, and then attempt to create an external library. The SQL Server instance has R version 3.4.3 (2017-11-30) and I do have R-3.6.0 installed on my laptop. There was a change in the workspace format version from 2 to 3 with R-3.5.0. So I think I get why this error is happening, but I can't fix it or pin point the exact step it occurs.

I have switched to using R-3.4.3 by installing it and changing it under Global Options in RStudio. I had to install all the necessary packages after that.

Here's by basic code:

# This should switch to version 2 for everything
Sys.setenv(R_DEFAULT_SAVE_VERSION = 2)
Sys.setenv(R_DEFAULT_SERIALIZE_VERSION = 2)

# Build a little model for testing
library(xgboost)
data_set <- data.frame(x1 = c(rnorm(10, mean = 2.5, sd = .1),
                              rnorm(10, mean = 7.5, sd = .1),
                              rnorm(10, mean = 2.5, sd = .1),
                              rnorm(10, mean = 7.5, sd = .1)),
                       x2 = c(rnorm(10, mean = 2.5, sd = .1),
                              rnorm(10, mean = 7.5, sd = .1),
                              rnorm(10, mean = 7.5, sd = .1),
                              rnorm(10, mean = 2.5, sd = .1)),
                       y = c(rep(0, 20), rep(1, 20)))
tree_mod <- xgboost(data = as.matrix(data_set[, c("x1", "x2")]), label = data_set$y,
                    nrounds = 2)
summary(tree_mod)

Then I save this model for use in the internal package.

usethis::use_data(tree_mod, internal = TRUE, overwrite = TRUE, version = 2) # Should use version 2

# Using devtools
document()
check() # Warning: package 'xgboost' was built under R version 3.4.4
devtools::build(binary = TRUE) 
# I am getting "-  using R version 3.4.3 (2017-11-30)" in the output

I also have an exported function that uses this model to predict to observations. I can install this on my laptop and everything is working.

Then I copy the zip file over to SQL Server and run this code:
CREATE EXTERNAL LIBRARY [RSTestPackage] FROM (CONTENT = 'C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\RSTestPackage_0.1.1.zip') WITH (LANGUAGE = 'R');
which results in the error.

I've tried everything I can find (environment variables, switch R versions, checking function parameter options, double checking moving the right files). I had this set up working previously and I guessing updating R broke it somehow, but I could be wrong. I have no clue how I'm still getting R 3.6.0 in the error message since switching to R 3.4.3 should have fixed that.

My next steps are to wipe R from my laptop, reset it all up again using only R 3.4.3, and use the checkpoint package to only use older packages. But I feel like that's pretty drastic and there should be an easier way.

That's really strange! I wanted to comment here since it has been two weeks and this post has not had any input. Unfortunately, I know next to nothing about R in SQL Server, or this "workspace version" format you are running into errors with. I would explore whether or not removing R 3.6.0 or using a server without R 3.6.0 installed helps. I don't know enough to say whether there could be some type of cross-linking / some other shady business happening for the different R versions on your desktop.

My aim would be to try a computer without any knowledge of R 3.6.0 first and see if that helps! Sorry I don't have more constructive feedback!

1 Like

I am getting the same error. I will follow the steps and report back if it works or not.

Error in readRDS(pfile) : 
  cannot read workspace version 3 written by R 3.6.1; need R 3.5.0 or newer
Calls: source ... library -> find.package -> lapply -> FUN -> readRDS

BTW This is really a misleading error message.


EDIT: I have re-installed R 3.3.3 for windows, because I am running SQL Server 2017. It seems working, but I got conflicting dependency errors....


EDIT 2: After I downloaded dependent packages for version 3.3.3 from https://cran.r-project.org/bin/windows/contrib/3.3/ and installed them to SQL Server 2017, it finally worked!

1 Like

Got the same error when I upgraded R. The solution was to update packages and make sure Environment variables pointed to the new R folder.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.