1

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.

Ramnath
  • 54,439
  • 16
  • 125
  • 152
Mutuelinvestor
  • 3,384
  • 10
  • 44
  • 75

1 Answers1

3

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)
Hong Ooi
  • 56,353
  • 13
  • 134
  • 187
  • Thanks for catching the typo in my code. `stringsAsFactors = FALSE` does fix things in R. – Ramnath Jun 27 '15 at 17:08
  • I did some research and decided to try a Trim function. That did the trick. Do you know if being a factor would lead to whitespace? – Mutuelinvestor Jun 28 '15 at 01:37
  • @Mutuelinvestor `trim` isn't a base R function but I'm guessing it converts its argument to character. This is what fixes the problem, not whether there's whitespace. – Hong Ooi Jul 01 '15 at 09:36