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.