title: SQL R Code The tutorial problem , Predict From Model wont run. Unserialize Error
body: <p>I ve created a model In R server , the tutorial example on the microsoft site. I have read simila texts /problems and the resolution was to wrap the model in as.raw befpore unserialize ..this does not help!!.</p>
  
  <p>Note I am new to this and have not seen a resolution. I refer to the script on the page 
  "Quickstart: Predict from model using R in SQL Server" on the Microsoft site ie </p>
  
  <p>DECLARE @glmmodel varbinary(max) = 
          (SELECT model FROM dbo.GLM_models WHERE model_name = 'default model');</p>
  
  <pre><code>EXEC sp_execute_external_script
      @language = N'R'
      , @script = N'
              current_model &lt;- unserialize(as.raw(glmmodel));                                           
              new &lt;- data.frame(NewMTCars);
              predicted.am &lt;- predict(current_model, new, type = "response");
              str(predicted.am);
              OutputDataSet &lt;- cbind(new, predicted.am);
              '
      , @input_data_1 = N'SELECT hp, wt FROM dbo.NewMTCars'
      , @input_data_1_name = N'NewMTCars'
      , @params = N'@glmmodel varbinary(max)'
      , @glmmodel = @glmmodel
  WITH RESULT SETS ((new_hp INT, new_wt DECIMAL(10,3), predicted_am DECIMAL(10,3)));
  </code></pre>
  
  <p>I get the following error :</p>
  
  <pre><code>DECLARE @glmmodel varbinary(max) = 
      (SELECT model FROM dbo.GLM_models WHERE model_name = 'default model');
  
  EXEC sp_execute_external_script
      @language = N'R'
      , @script = N'
              current_model &lt;- unserialize(as.raw(glmmodel));                                           
              new &lt;- data.frame(NewMTCars);
              predicted.am &lt;- predict(current_model, new, type = "response");
              str(predicted.am);
              OutputDataSet &lt;- cbind(new, predicted.am);
              '
      , @input_data_1 = N'SELECT hp, wt FROM dbo.NewMTCars'
      , @input_data_1_name = N'NewMTCars'
      , @params = N'@glmmodel varbinary(max)'
      , @glmmodel = @glmmodel
  WITH RESULT SETS ((new_hp INT, new_wt DECIMAL(10,3), predicted_am DECIMAL(10,3)));
  </code></pre>
  
  <p>I get the following error :</p>
  
  <p>"Msg 39004, Level 16, State 20, Line 44
  A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
  Msg 39019, Level 16, State 2, Line 44
  An external script error occurred: 
  During startup - Warning message:
  In setJsonDatabasePath(system.file("extdata/capabilities.json",  :
    bytecode version mismatch; using eval
  Error in unserialize(as.raw(glmmodel)) : read error
  Calls: source -> withVisible -> eval -> eval -> unserialize</p>
  
  <p>Error in execution.  Check the output for more information.
  Error in eval(expr, envir, enclos) : 
    Error in execution.  Check the output for more information.
  Calls: source -> withVisible -> eval -> eval -> .Call
  Execution halted
  "
  Is the error related to <em>unserialize</em> or is it related to"</p>
  
  <p>During startup - Warning message:
  In setJsonDatabasePath(system.file("extdata/capabilities.json",  :
    bytecode version mismatch; using eval</p>