How to prevent a different output from the Alteryx R tool
- How-Tos FAQs
- July 8, 2021
How to prevent a different output from the Alteryx R tool
In this article, we will discuss some of the leading causes of incorrect different output when you use Alteryx R Tool to sign an amazon HTTP request.
An incorrect output can result from many things, including wrong field conversion, connection error, wrong entry/input and much more.
We will use the HMAC function included in the digest package and a text input tool that includes the key and a date stamp to sign an amazon HTTP request.
Key= "foo"
datastamp= "20120215"
When we run our first script below:
the.data <- read.Alteryx("1", mode-"data.frame")
write.Alteryx(base64encode(hmac(the.data$key,the.data$datestamp,algo="sha256",raw = TRUE)),1
We get an incorrect result as compared to when we run the following:
write.Alteryx(base64encode(hmac("foo","20120215",algo-"sha256",raw = TRUE)),1)
The difference being when we hardcode the values for the key and object, we get the correct result. But if we use the variables from the R data frame, we get incorrect output.
Alteryx can READ data as a data frame or as a list. While many common Alteryx R Tool issues arise from trying to read/write objects of the incorrect class, this may or may not cause the incorrect output.
Let’s delve into the possible leading causes of our incorrect output. Firstly, let’s understand if the DATA FRAME could have altered the data.
Does the data frame alter the data in some way?
As a recommended practice, you should use the data.frame() R function to convert the data to a data frame before using the write.Alteryx() function.
Alteryx will attempt to transform data to a data frame if one has not already been converted; however, this conversion may not go as planned and result in inaccurate output.
You can also use the class() function to check whether your variable is a data frame.
> x
SN AGE Name
1 1 21 John
2 2 15 Dora
> typeof(x) # data frame is a special case of list
[1] "list"
> class(x)
[1] "data.frame"
The difference in the text input
The incorrect output can again result from the difference in the text input; ‘datastamp’ or ‘datestamp’? It should be ‘datestamp.’
If the column title in the text input tool is ‘datastamp’ but not ‘datestamp’;
Then the “datestamp” in this script will give incorrect output as it is not detected.
Conversion error
Lastly, the incorrect output can also result from one of these variables not being detected by the R Tool.
If this is the case, it can be the “date stamp” with the problem. Often in R, you have to specify the date class.
as.Date(variable,"%m/%d/%Y")
But Alteryx will take a different format:
as.Date(variable,"%Y-%m-%d")
If a Date value is not in this format, Alteryx reads it as a string, which can sometimes give incorrect output. Always specify the date class or use the DateTimeParse function in the expression editor to convert the column into date format.
The answers in this brief guide provided a solution to the error.