我有一个代表对象状态的数字,我想检查其中一个状态。例如,如果数字是“22”,它应该在检查 16、4 或 2 时返回 true,而对于其他任何值都返回 false。我的功能是
containsOrderType <- function(orderType, state) #returns whether the bitmask translates to containing that order type
{
state <- as.numeric(state)
if(orderType>state) return(FALSE)
binState <- as.integer(state)
class(binState) <- "binmode"
binState <- as.character(binState)
dim(binState) <- dim(state)
X<-log2(orderType)+1
if(str_sub(binState,-X,-X)==1) return(TRUE)
return(FALSE)
}
直到今天这一个月都运行良好,我很确定问题在于 dim(state) 正在采用 dim([an integer]) 似乎总是“NULL”。这发生在 R 2.15.3 和 R 3.0.1 中。如果那是一致的,我会得到它,但是这个功能在一段时间内完全按照预期工作,现在它没有。这是 R.Utils 中的 intToBin 函数,它与我的函数的第 3-6 行相同。
function (x)
{
y <- as.integer(x)
class(y) <- "binmode"
y <- as.character(y)
dim(y) <- dim(x)
y
}
还
>dim
function (x) .Primitive("dim")
> class
function (x) .Primitive("class")
所以那些还没有被包或类似的奇怪东西覆盖。