1

I am new to the IRanges package and am having trouble getting the end value of an IRange. I am able to get the start and width values with no problem, which has me a bit baffled, and my case/spelling of end match the header line. Has anyone else run into this or can please spot what I am doing wrong? Thanks and it is much appreciated!

library(IRanges)
> test=IRanges(100645,100664)

> test
IRanges of length 1
 start    end width
[1] 100645 100664    20

> test@start
[1] 100645

> test@width
[1] 20

> test@end
Error: no slot of name "end" for this object of class "IRanges"
rattlerray
  • 63
  • 1
  • 1
  • 4
  • 4
    In general (and for your future reference), you should consider the slots "private" and shouldn't be accessing their values directly via `@`. If the package developer wants to give you access to something, they will do so via an accessor function, eg. `width(test)`, `start(test)` or `end(test)`, as Lianzinho pointed out – Steve Lianoglou Mar 17 '12 at 21:01

2 Answers2

3

The easiest manner to access the fields of an IRange object is using the helper functions: start(),end() and width(). These will return a vector with all the elements of the corresponding column.

Halian Vilela
  • 371
  • 1
  • 4
  • 13
  • Thanks! Very strange that the @ notation worked for two of the three fields, but will now use the helper methods. Much appreciated! – rattlerray Mar 17 '12 at 05:11
  • @rattlerray that's because the `@end` slot does not exist at all. You can see it by typing `str(IRange_object)`. Just the `@start` and `@width` are defined. Probably the `end` is calculated from them. – Halian Vilela Mar 22 '12 at 01:14
1

No experience with the package, but based on ?"class:Ranges":

end(test$ranges[1])

It would also help in the future to provide reproducible sample data.

attitude_stool
  • 1,023
  • 1
  • 13
  • 18
  • Sorry about that. I forgot to paste in the line where I actually declared the IRange. Worked great. Thanks! – rattlerray Mar 17 '12 at 05:10