R:与 numpy 的 .dtype.itemsize 和 .dtype.alignment 数组属性等价的 R 是什么?

R: What's the R equivalent to numpy's .dtype.itemsize and .dtype.alignment array properties?

我正在尝试将类似的内容从 python 转换为 R:

dt = my_array.dtype
fw = int(dt.itemsize/dt.alignment)
b = numpy.array([list(w.ljust(fw)) for w in my_array.T])

我环顾四周,但没有找到关于这个特定主题的任何内容。

第一行提取数据类型。 R 可能使用 class(my_array)。也可以使用 typeof 或 mode ,但除非您研究了 R 一段时间,否则您可能无法获得所需的信息。 Python 似乎在数据类型字符串中编码了几种类型的信息。 R 中并没有真正的平行关系,但您可能想查看 str() 返回的值。与 Python 的 dt 不同,str 中的值将无法通过其他函数进行进一步分解。从它的帮助页面:

Value

str does not return anything, for efficiency reasons. The obvious side effect is output to the terminal.

attributes 函数有时会产生有关对象的附加信息,但在数组的情况下,除了来自 dim.

的信息外,没有任何附加信息。
> my_array <- array(1:24, c(2,3,4))  # a 2 x 3 x 4 array of integers
> class(my_array)
[1] "array"
> str(my_array)
 int [1:2, 1:3, 1:4] 1 2 3 4 5 6 7 8 9 10 ...
dim(my_array)   # Not sure, but this might be the equivalent of "alignment"
[1] 2 3 4
 attributes(my_array)
$dim
[1] 2 3 4
> length(my_array)
[1] 24
> mode(my_array)
[1] "numeric"