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.
Ruby Rserve gem을 사용 하고 다음과 같이 R S4 객체와 상호 작용 하여 데이터를 얻었습니다 .
con = con=Rserve::Connection.new
r_edges = con.eval("SOME S4 OBJECT").to_ruby
배열을 반복 할 때 '명명 된 인덱스'데이터를 얻는 것이 실제로 도움이되지만 해당 값에 액세스하는 방법을 모르겠습니다.
Ruby는 굉장하기 때문에 재미있게 행동합니다! 이를 통해 서브 클래 싱하지 않고도 기능을 객체에 밀어 넣을 수 있습니다.
Rserve gem의 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 행을 살펴보세요).
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다