为什么我从Alteryx R工具获得不同的输出

为什么我从Alteryx R工具获得不同的输出,r,alteryx,R,Alteryx,我使用Alteryx R工具对amazon http请求进行签名。为此,我需要摘要包中包含的hmac函数 我使用的是一个文本输入工具,包括键和日期戳 Key= "foo" datastamp= "20120215" 问题就在这里。当我运行以下脚本时: the.data <- read.Alteryx("1", mode="data.frame") write.Alteryx(base64encode(hmac(the.data$key,the.data$datestamp,algo="s

我使用Alteryx R工具对amazon http请求进行签名。为此,我需要摘要包中包含的hmac函数

我使用的是一个文本输入工具,包括键和日期戳

Key= "foo"
datastamp= "20120215"
问题就在这里。当我运行以下脚本时:

the.data <- read.Alteryx("1", mode="data.frame")
write.Alteryx(base64encode(hmac(the.data$key,the.data$datestamp,algo="sha256",raw = TRUE)),1)
区别在于,当我硬编码键和对象的值时,我得到了正确的结果。但是如果使用R数据帧中的变量,我会得到不正确的输出

数据帧是否以某种方式改变了数据。在Alteryx中使用R工具时,是否有人遇到过这种情况


谢谢你的意见

问题似乎是,在创建数据帧时,角色变量会转换为因子。使用
data.frame
构造函数修复此问题的方法是

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

谢谢你抓住了我代码中的错误
stringsAsFactors=FALSE
确实修复了R中的问题。我做了一些研究,决定尝试一个修剪函数。这就成功了。你知道作为一个因子是否会导致空白吗?@Mutuelinvestor
trim
不是一个基本的R函数,但我猜它会将其参数转换为字符。这是解决问题的方法,而不是是否有空格。
the.data <- data.frame(Key="foo", datestamp="20120215", stringsAsFactors=FALSE)
write.Alteryx(base64encode(hmac(
    as.character(the.data$Key),
    as.character(the.data$datestamp),
    algo="sha256",raw = TRUE)),1)