I'm using an r script visual in PowerBI. I can run the below code in R and it works, but I get the error below when running in PowerBI. I want to show the results from apriori in a visual. Both tests below run fine in R, but NOT in R script visual from PowerBI. Any thoughts?
if I try #test2.
library(Matrix)
library(arules)
library(plyr)
library(gridExtra)
df_itemList <- ddply(dataset,c("SALESID"),function(df1)paste(df1$ITEMID))
#test1
#df_itemList = sapply(df_itemList , function(x) gsub(" ", ",", x))
#basket_rules <- apriori(df_itemList, parameter = list(sup=0.1,conf=0.5,target="rules", maxlen=5));
#test2
txn = read.transactions(df_itemList, rm.duplicates = TRUE, format = "basket", sep = ",", cols = 1);
basket_rules <- apriori(txn, parameter = list(sup=0.1,conf=0.5,target="rules", maxlen=5));
df_basket <- as(basket_rules,"data.frame")
grid.table(df_basket)
Error Message: R script error.
Attaching package: 'arules'
The following objects are masked from 'package:base':
abbreviate, write
Error in readLines(file, encoding = encoding) : 'con' is not a connection Calls: read.transactions -> lapply -> readLines Execution halted
If I try #test1...
library(Matrix)
library(arules)
library(plyr)
library(gridExtra)
df_itemList <- ddply(dataset,c("SALESID"),function(df1)paste(df1$ITEMID))
#test1
df_itemList = sapply(df_itemList , function(x) gsub(" ", ",", x))
basket_rules <- apriori(df_itemList, parameter = list(sup=0.1,conf=0.5,target="rules", maxlen=5));
#test2
#txn = read.transactions(df_itemList, rm.duplicates = TRUE, format = "basket", sep = ",", cols = 1);
#basket_rules <- apriori(txn, parameter = list(sup=0.1,conf=0.5,target="rules", maxlen=5));
df_basket <- as(basket_rules,"data.frame")
grid.table(df_basket)
Then I get the error below.
Error Message: R script error.
Attaching package: 'arules'
The following objects are masked from 'package:base':
abbreviate, write
Error in asMethod(object) : column(s) 2, 3, 4 not logical or a factor. Discretize the columns first. Calls: apriori -> as -> asMethod Execution halted
read.transactions
call in the code you posted is commented out, yet your error message contains that call. Is the commented out code part of what you ran? If so, the error is unrelated to R vs PowerBI and simply due to the fact that you didn’t pass a filename to theread.transactions
call but a dataframe. – Konrad Rudolphapriori
correctly, and, in particular, how to construct a “transactions” object that can be passed to theapriori
function (section 5.2; although you can also pass the data frame directly). — Anyway, this really has nothing to do with R vs Power BI. – Konrad Rudolph