Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
patipati
Frequent Visitor

Importing Rds R model to Power BI - gam model

Hi,

 

 

I'm trying to pass parameters of Gam model using this method.

 

https://towardsdatascience.com/how-to-predict-values-from-a-custom-r-model-in-power-bi-3364f83b0015

 

Unfortunettaly I am gettign read error on unserialize function

 

from_byte_string = function(x) {
xcharvec = strsplit(x, " ")[[1]]
xhex = as.hexmode(xcharvec)
xraw = as.raw(xhex)
unserialize(xraw)

 

}

#project_folder <- "Z:/Datasets/NSA/EBITDA_adimensional/"
#finalfit <- readRDS(paste0(project_folder, "mtcars-model.rds"))

finalfit.str <- as.character( dataset[dataset$model_id == 1, "model_str"] )
finalfit <- from_byte_string(finalfit.str)

v <- c( wt=dataset$weight, qsec=dataset$qsec, am=as.factor(dataset$am) )

pred <- round( predict(finalfit, newdata = as.data.frame(t(v))), digits = 2 )

plot.new()
text(0.5, 0.5,
#labels = as.character(dataset$weight)
labels = as.character(pred[[1]])
,cex = 3.5
)
 
On IDE script is runnig properly.
 
Is there anyone who had tried it yet ? Can it be problem with library in Power BI ?
 
 
3 REPLIES 3
v-chuncz-msft
Community Support
Community Support

@patipati 

 

That works for me. Try the latest version of Power BI Desktop and take a good look at Create Power BI visuals with R.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

I have March version, and R 3.5.3 and I'm still getting error with unserialize function:

 

unserialize(xraw): read error

Anonymous
Not applicable

Where you able to solve this issue?

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.