title: How to convert any object in character in R?
body: <p>I use <code>wordnet</code> library and I want to get the wordnet index of a token for future purpose. </p>
  
  <pre><code>library(wordnet)
  filter &lt;- getTermFilter("ExactMatchFilter", "proud", TRUE)
  terms &lt;- getIndexTerms("ADJECTIVE", 1, filter)
  terms
  
  
  [1] "Java-Object{Lemma: proud  POS: adj  Tag-Sense-Count: 2\nList of Synsets (2)\n  #1: 1817423\n  #2: 1231908\nList of Pointers (4)\n  #1: ! (Antonym)\n  #2: &amp; (Similar to)\n  #3: ^ (Also see)\n  #4: = (Attribute)}"
  </code></pre>
  
  <p>terms is a Java-Object with some methods : </p>
  
  <pre><code>names(terms[[1]])
  [1] "getLemma()"         "getSynsets()"       "getPointers()"      "getPartOfSpeech()"  "getSynsetCount()"   "getTagSenseCount()" "getPointerCount()" 
  [8] "toString()"         "compareTo("         "compareTo("         "wait("              "wait("              "wait()"             "equals("           
  [15] "hashCode()"         "getClass()"         "notify()"           "notifyAll()"    
  </code></pre>
  
  <p>but they don't all work, it seems</p>
  
  <pre><code>getLemma(terms[[1]])
  [1] "proud"
  
  toString(terms[[1]])
  Erreur dans as.character.default(&lt;S4 object of class "jobjRef"&gt;) : 
  pas de méthode pour convertir automatiquement cette classe S4 en vecteur
  </code></pre>
  
  <p>I want to extract the code, here "#1: 1817423" from terms[[1]], I thought I could use substring or regex but so far I just can't convert the object in string so that I can work with it. Any idea ?</p>
  
  <pre><code>str(terms[[1]]) 
  Formal class 'jobjRef' [package "rJava"] with 2 slots
  ..@ jobj  :&lt;externalptr&gt; 
  ..@ jclass: chr "java/lang/Object"
  
  unclass(terms[[1]])
  &lt;S4 Type Object&gt;
  attr(,"jobj")
  &lt;pointer: 0x000000000cb81050&gt;
  attr(,"jclass")
  [1] "java/lang/Object"
  </code></pre>