R SQL Server file does not exist error - but it does

307 Views Asked by At

I'm running R 3.5.2 inside SQL Server 2019.

Loading the pre-trained udpipe model using the following command:

udmodel_english <- udpipe_load_model(file = ''C:/ud/english-ewt-ud-2.5-191206.udpipe'')

This works fine in Rstudio, and R directly. However when running as a SQL External script I get the following error:

Error in udpipe_load_model(file = "C:/ud/english-ewt-ud-2.5-191206.udpipe") : 
  File C:/ud/english-ewt-ud-25-191206.udpipe containing the language model does not exist
Calls: source -> withVisible -> eval -> eval -> udpipe_load_model

However the file is there, it does exist, and loads via Rstudio with no issue.

Any suggestions would be extremely helpful.

Full code as FYI:

Begin
EXEC sp_execute_external_script       
@language = N'R',
@script = N' 

library(zoo)
library(xts)
library(udpipe)

#model <- udpipe_download_model(language = "english")
udmodel_english <- udpipe_load_model(file = ''C:/ud/english-ewt-ud-2.5-191206.udpipe'')
'
End

Full error as FYI:

Msg 39004, Level 16, State 20, Line 29
A 'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004.
Msg 39019, Level 16, State 2, Line 29
An external script error occurred: 

Attaching package: 'zoo'

The following objects are masked from 'package:base':

    as.Date, as.Date.numeric

Error in udpipe_load_model(file = "C:/ud/english-ewt-ud-2.5-191206.udpipe") : 
  File C:/ud/english-ewt-ud-25-191206.udpipe containing the language model does not exist
Calls: source -> withVisible -> eval -> eval -> udpipe_load_model
In addition: Warning messages:
1: package 'zoo' was built under R version 3.5.3 
2: package 'xts' was built under R version 3.5.3 
3: package 'udpipe' was built under R version 3.5.3 

Error in execution.  Check the output for more information.
Error in eval(ei, envir) : 
  Error in execution.  Check the output for more information.
Calls: runScriptFile -> source -> withVisible -> eval -> eval -> .Call
Execution halted

Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

I've done it. (Finally!!)

Yes, it was a permissions issue, but not like you would expect. Aside from SQL having access to the folder, to have R access a file folder outside of working directory. You have to give permissions to "ALL APPLICATION PACKAGES" object to that folder.

Hope that saves anyone else the hours of piecing together google bits.