How to slice association rules DataFrame in R Server?

0

I have below code to process association rules inside R Server. This Works totally fine outside R Server, but when I adapt the codes to run inside SQL Server 2016 I get error.

"Target" in this case is what the PartID I want to filter.

SELECT BK_PARTID, CorpOrderID INTO #TEMP FROM ARTransactions 
DECLARE @SQLQuery NVARCHAR(MAX) = N'SELECT * FROM #TEMP'
DECLARE @RScript NVARCHAR(MAX) = 
'
library(arules)

TransactionsDataSet = as(split(StoreTransactions[,"BK_PartID"], StoreTransactions[,"CorpOrderID"]),"transactions")

Target = 10092007

filtered_rules = apriori(data = TransactionsDataSet, parameter = list(supp = 0.001, conf = 0.20, minlen = 2),appearance = list(default = "rhs", lhs = c(Target)),control = list(verbose = F))

#filtered_rules = inspect(filtered_rules[1:10])

#filtered_rules <- head(as(sort(filtered_rules, decreasing = TRUE, na.last = NA, by = "confidence"), "data.frame"), 30);

'

EXEC sp_execute_external_script 
@Language = N'R',
@Script = @RScript,
@input_data_1 = @SQLQuery,
@input_data_1_name = N'StoreTransactions',
@parallel = 1,
@output_data_1_name = N'filtered_rules'

WITH RESULT SETS ((Rules VARCHAR(MAX), Support FLOAT, Confidense FLOAT, Lift FLOAT));

ERROR:

(591112 row(s) affected) Msg 39004, Level 16, State 20, Line 14 A 

'R' script error occurred during execution of 'sp_execute_external_script' with HRESULT 0x80004004. Msg 39019, Level 16, State 1, Line 14

An external script error occurred: Carregando pacotes exigidos: Matrix

Attaching package: 'arules'

The following objects are masked from 'package:base':
%in%, abbreviate, write

Error in asMethod(object) : 10092007 is an unknown item label Calls: source ... withVisible -> eval -> eval -> apriori -> as -> asMethod

Error in ScaleR. Check the output for more information. Error in eval(expr, envir, enclos) : Error in ScaleR. Check the output for more information. Calls: source -> withVisible -> eval -> eval -> .Call

OBS. This PART exists in Dataset.

Could not find anything equal and inside RStudio, Works fine.

ANyone has any idea why this is not working?

sql-server
r
visual-studio-2015
sql-server-2016
asked on Stack Overflow Jul 19, 2017 by Bruno.hca • edited Jul 20, 2017 by McGrady

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0