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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Sebas2905
Frequent Visitor

Error using R script transforming data

Hi 

 

I want to use R in Power Query to create a HMAC-SHA1 signature in Power Query. The R-Script I want to run is the following:


library(httr)

key <- "Key"
string <- "String"

signature <- sha1_hash(key, string, method = "HMAC-SHA1")

 

This script works perfectly in RStudio. To use it in Power Query I created a table with a Key column and a String column by using Enter Data. I want the R script to create a signature for every combination of Key and String on every row. The table I created is this:

Knipsel.PNG

 

To run the script I added the step Run R script1 and added the following R script:

 

# 'dataset' holds the input data for this script

library(httr)


key <- dataset$"Key"
string <- dataset$"String"

signature <- sha1_hash(key, string, method = "HMAC-SHA1")

output <- dataset

output$signature <- signature

 

This results in the following error:

 

DataSource.Error: ADO.NET: R script error.
Error in rawstringhash(x, "sha1", key) :
Argument 'x' must be raw or character vector.
Calls: sha1_hash -> <Anonymous> -> rawstringhash
Execution halted

Details:
DataSourceKind=R
DataSourcePath=R
Message=R script error.
Error in rawstringhash(x, "sha1", key) :
Argument 'x' must be raw or character vector.
Calls: sha1_hash -> <Anonymous> -> rawstringhash
Execution halted

ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException

 

Does anyone know why this script won't run? If I replace the parameters key and string with plain text the script works fine, but doesn't calculate the signature per row. So it doesn't recognize my rows as valid parameters in the R script.

 

# 'dataset' holds the input data for this script

library(httr)


key <- "Key"
string <- "String"

signature <- sha1_hash(key, string, method = "HMAC-SHA1")

output <- dataset

output$signature <- signature

 

Knipsel1.PNG

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Sebas2905 

Check if changing dataset$column1 to as.character(dataset$column1) would work.

 

 

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

View solution in original post

4 REPLIES 4
michaelsh
Kudo Kingpin
Kudo Kingpin

@Sebas2905  @v-juanli-msft 

Do you know if it (R script) will work in the service...?

@michaelsh 

 

it works if you use a gateway (enterprise or personal) with R installed on it. 

best regards, Sebastiaan

v-juanli-msft
Community Support
Community Support

Hi @Sebas2905 

Check if changing dataset$column1 to as.character(dataset$column1) would work.

 

 

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

Hi Maggie,

 

It works! Thanks.

 

Best regards,

 

Sebastiaan

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

Check out the September 2024 Power BI update to learn about new features.

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors