1

I have a long R-script file and I would like to use SQL Server R Services, reading about its documentation, I have not seen any example of using: sp_execute_external_script that allows loading an R-script file. All examples are intended to use simple r-computation embedded in a SQL sentences, such as the following example:

DROP PROC IF EXISTS get_iris_dataset;  
go  
CREATE PROC get_iris_dataset  
AS  
BEGIN  
EXEC   sp_execute_external_script  
   @language = N'R'  
 , @script = N'iris_data <- iris;'  
 , @input_data_1 = N''  
 , @output_data_1_name = N'iris_data'  
 WITH RESULT SETS (("Sepal.Length" float not null,   
       "Sepal.Width" float not null,  
    "Petal.Length" float not null,   
    "Petal.Width" float not null, "Species" varchar(100)));  
END;  
go  

I would need in some way to use the r-sentence source("fileName") for executing the r-sentences.

Note: I am trying to use an SQL Server just because a better machine performance than my personal computer.

Thanks in advance,

David

1
  • 1
    Are the R script files you are trying to source saved on the SQL Server machine? If so, you should be able to source then just like in R assuming there is read access to them. Commented Jul 23, 2016 at 0:34

1 Answer 1

5

It is certainly possible to use source("filename") you execute an R script. The R script should be located somewhere SQL Server has access to it. For instance: source("C:/Rscripts/script.R"). Note that SQL Server has no access to your My Documents folder...

EXEC sp_execute_external_script
@language = N'R'
,@script = N'
source("C:/Rscripts/script.R");'
,@input_data_1 = N''  
,@output_data_1_name = N'iris_data'  
WITH RESULT SETS (("Sepal.Length" float not null,   
 "Sepal.Width" float not null,  
 "Petal.Length" float not null,   
 "Petal.Width" float not null, "Species" varchar(100)));  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.