title: General way to transform S4 object to dataframe (R)
body: <p>I have a number of S4 objects with a variable number of slots and slotnames. The data in each slot is the same length. For example the S4 object <code>peaks</code>:</p>
  
  <pre><code>&gt; str(peaks)
  Formal class 'MassPeaks' [package "MALDIquant"] with 4 slots
    ..@ snr      : num [1:16] 37.81 9.18 8.65 4.66 53.22 ...
    ..@ mass     : num [1:16] 307 317 325 337 347 ...
    ..@ intensity: num [1:16] 2255 547 516 278 3173 ...
    ..@ metaData : list()
  </code></pre>
  
  <p>I want to turn these S4 objects into dataframes. For example the dataframe <code>df.peaks</code>:</p>
  
  <pre><code>&gt; str(df.peaks)
  'data.frame':   16 obs. of  3 variables:
   $ snr      : num  37.81 9.18 8.65 4.66 53.22 ...
   $ mass     : num  307 317 325 337 347 ...
   $ intensity: num  2255 547 516 278 3173 ...
  </code></pre>
  
  <p>Is there a general way to do this? For this example I can do</p>
  
  <pre><code>&gt; df.peaks = data.frame(snr=peaks@snr, mass=peaks@mass, intensity=peaks@intensity)
  </code></pre>
  
  <p>but that requires hardcoding the slotnames of the S4 object. <strong>How do I do it without hardcoding the slotnames?</strong> I could do it by getting <code>s4.names = slotNames(peaks)</code>, but in this case I don't know how to use <code>s4.names</code> to access the slots of <code>peaks</code>.</p>