1

I've been struggling with this issue for a while, and I think that there is an easy solution that I'm just not seeing. I called a function on a vector, and what is returned is a list of lists, with one list for each value in the original vector. Here is the beginning of the output of that function, showing only the first list in the list of lists:

> getGOParents(go1769308.mf)[1]
$`GO:0003824`
$`GO:0003824`$Ontology
[1] "MF"

$`GO:0003824`$Parents
        is_a 
"GO:0003674" 

I'd like to only get the last value, "GO:0003674". Is this possible? Here is the structure of the list if it is of any help:

> str(getGOParents(go1769308.mf)[1])
List of 1
 $ GO:0003824:List of 2
  ..$ Ontology: chr "MF"
  ..$ Parents : Named chr "GO:0003674"
  .. ..- attr(*, "names")= chr "is_a"

The values I'm looking for are in the component $Parents, but I can't seem to access it:

> Parents(getGOParents(go1769308.mf)[1])
Error: could not find function "Parents"
> 
> getGOParents(go1769308.mf)[1]$Parents
NULL

I may be misunderstanding the utility of components, and hence why I'm struggling with this.

J0HN_TIT0R
  • 323
  • 1
  • 13

1 Answers1

0

We need to use [[ to extract the list

getGOParents(go1769308.mf)[[1]]$Parents

The reason OP's code didnt' work was using [ the nested list component stays as nested

akrun
  • 874,273
  • 37
  • 540
  • 662
  • 1
    Wow, that's it, I can't believe it was that easy, thanks you! – J0HN_TIT0R Mar 24 '17 at 02:52
  • I know it's a bit separate from the original question, but is there a way to get all values of $Parents from each list without doing a for loop? – J0HN_TIT0R Mar 24 '17 at 02:53
  • @J0HN_TIT0R Since it is a nested list, you can use lapply i.e. `lapply(getGOParents(go1769308.mf, function(x) x$Parents)` – akrun Mar 24 '17 at 02:55