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
Anonymous
Not applicable

Same R script, different results

I tried the below R script in two different places on PowerBI but it gives me a different results

on Get Data > R script, the following R script returns a dataset that I can explain and eventually parse JSON format.

On the other hand, when applying this on Run R Script within Transform - it doesnt return any dataset that I can do further transformation. Basically returns no rows. What have I done wrong? Please find R script below. Note that I took away my API key 🙂 - Many thanks

 

# 'dataset' holds the input data for this script
library(rosetteApi)

key <- "content"
value <- "It is a beautiful day"
parameters <- list()
parameters[[ key ]] <- value
parameters <- toJSON(parameters)
result = api("my api", "sentiment", parameters)
myjson <- toJSON(result)

dataset <- as.data.frame(myjson)

 

3 REPLIES 3
jb1t
Advocate I
Advocate I

From what I've been able to determine at this point you need to return a data.frame named exactly "output".

 

So I usually start with:

 

output <- dataset

# do manipulations add columns etc... to the output data frame

v-sihou-msft
Microsoft Employee
Microsoft Employee

@Anonymous

 

The R script under "Get Data" is for importing the resulting data frame. But the R script in Query Editor is only for performing transformation and shaping data.

 

Reference:
Running R Scripts in Power BI Desktop

Using R in Query Editor

 

Regards,

Anonymous
Not applicable

hi there

Im aware of that, however my problem is why one gives me an error and the other doesnt so it must be a bug? 

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.