在将数据从R插件导入到我的红宝石脚本之后,我有一个看起来像散列的数组。有人知道这是怎么回事吗?
r_edges.class
#=> Array < Object
r_edges[0]
#=> returns data from index 0 as expected
r_edges['GO:0010035']
# r_edges['GO:0010035']['edges'] also works
#=> returns data at the index that is named 'GO:0010035', see the to_s output below
r_edges
#=> [ 0] [
[0] [
[ 0] 2,
[ 1] 3,
[ 2] 4,
[ 3] 5,
[ 4] 6,
[ 5] 7,
[ 6] 8,
[ 7] 9,
...... etc.
r_edges.to_s
#=> "[GO:0006260=[edges=[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28, 29, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 48, 51, 55, 56, 57, 58, 59, 60, 63, 67, 69, 71, 78, 81, 83, 84, 89, 90, 91, 92, 94, 95, 96, 97, 99, 100, 104, 108, 109, 112, 116, 117, 123, 124]], GO:0006271=[edges=[1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 28, 29, 36, 40, 46, 67]], GO:0022616=[edges=[1, 2, .... etc. 我通过使用红宝石并与R S4对象进行交互获得数据,如下所示:
con = con=Rserve::Connection.new
r_edges = con.eval("SOME S4 OBJECT").to_ruby在遍历数组时获取“命名索引”数据实际上很有帮助,但我不知道如何访问该值。
发布于 2014-04-03 22:32:36
它的行为很有趣,因为Ruby很棒!它允许您将功能推入对象而不对其进行子类划分。
从Rserve的rlist类
# Returns an Array with module WithNames included
# * Unnamed list: returns an Array
# * Named List: returns a Hash. Every element without explicit name receive
# as key the number of element, 1-based
#
def to_ruby
data=to_a
data.extend WithNames
data.names=@names
data
end它将WithNames模块插入到数组中,数组中有两个用于[]的方法(查看第121行)。
https://stackoverflow.com/questions/22850044
复制相似问题