HI Everyone
I have a problem with an R function that I am trying to execute on an SQL function.
I am attaching screenshots with eror message.
In RSudio, the code works without a problem, so I don't understand what causes this problem.
ALTER PROCEDURE HI (@threshold float = 0.1)
as
begin
exec sp_execute_external_script
@language = N'R',
@script = N'
library(reshape2);
dd = dcast(InputDataSet, VendorNumber ~ Digits, value.var="Freq");
OutputDataSet = cbind(
dd,
apply(dd[,-1], 1, function(xx) chisq.test(xx, p=(log(1+1/(1:9))/log(10)))$p.value)); ## Equation using Benford law
colnames(OutputDataSet) <- c("VendorNumber", "Digit1", "Digit2", "Digit3", "Digit4",
"Digit5", "Digit6", "Digit7", "Digit8", "Digit9", "Pvalue");
OutputDataSet <- subset(OutputDataSet, Pvalue < threshold);
',
@input_data_1 = N'
select VendorNumber, Digits, Freq
from [BenfordFraud].VendorInvoiceDigits(default)
order by VendorNumber asc, Digits asc;
',
@params = N'@threshold float',
@threshold = @threshold
with result sets (( VendorNumber varchar(10),
Digit1 int, Digit2 int, Digit3 int, Digit4 int, Digit5 int, Digit6 int, Digit7 int, Digit8 int, Digit9 int,
Pvalue float));
end;
Thank you in advance for your help