Search code examples
ralteryx

Why am I getting different output from the Alteryx R tool


I using the Alteryx R Tool to sign an amazon http request. To do so, I need the hmac function that is included in the digest package.

I'm using a text input tool that includes the key and a datestamp.

Key= "foo"
datastamp= "20120215"

Here's the issue. When I run the following script:

the.data <- read.Alteryx("1", mode="data.frame")
write.Alteryx(base64encode(hmac(the.data$key,the.data$datestamp,algo="sha256",raw = TRUE)),1)

I get an incorrect result when compared to when I run the following:

write.Alteryx(base64encode(hmac("foo","20120215",algo="sha256",raw = TRUE)),1)

The difference being when I hardcode the values for the key and object I get the correct result. But if use the variables from the R data frame I get incorrect output.

Does the data frame alter the data in someway. Has anyone come across this when working with the R Tool in Alteryx.

Thanks for your input.


Solution

  • The issue appears to be that when creating the data frame, your character variables are converted to factors. The way to fix this with the data.frame constructor function is

    the.data <- data.frame(Key="foo", datestamp="20120215", stringsAsFactors=FALSE)
    

    I haven't used read.Alteryx but I assume it has a similar way of achieving this.

    Alternatively, if your data frame has already been created, you can convert the factors back into character:

    write.Alteryx(base64encode(hmac(
        as.character(the.data$Key),
        as.character(the.data$datestamp),
        algo="sha256",raw = TRUE)),1)